Skip to content

Commit 31f9839

Browse files
authored
fix: always include anonymous & authenticated roles (#238)
1 parent bedc06d commit 31f9839

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/auth.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ <h1 class="pb-4">Azure Static Web Apps Auth</h1>
162162
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.2.1.min.js" crossorigin="anonymous"></script>
163163
<script src="https://ajax.aspnetcdn.com/ajax/bootstrap/4.1.1/bootstrap.min.js" crossorigin="anonymous"></script>
164164
<script>
165+
const defaultRoles = ["anonymous", "authenticated"];
165166
function saveCookie(formElement) {
166167
const data = localStorage[hashStorageKey(formElement)];
167168
document.cookie = `StaticWebAppsAuthCookie=${btoa(data)}; path=/`;
@@ -229,7 +230,8 @@ <h1 class="pb-4">Azure Static Web Apps Auth</h1>
229230
const inputValue = element.val();
230231
let data = JSON.parse(localStorage[storageKey]);
231232
if (inputName === "userRoles") {
232-
data[inputName] = inputValue.trim().split("\n");
233+
// ensure default roles are included
234+
data[inputName] = [...new Set([...inputValue.trim().split("\n"), ...defaultRoles])];
233235
} else {
234236
data[inputName] = inputValue;
235237
}
@@ -287,7 +289,6 @@ <h1 class="pb-4">Azure Static Web Apps Auth</h1>
287289
<script>
288290
$(function () {
289291
// setup default values
290-
const defaultRoles = ["anonymous", "authenticated"];
291292
const form = $("form[name='auth']");
292293

293294
// trigger on first call

0 commit comments

Comments
 (0)