Skip to content

Commit ffcb8db

Browse files
committed
fix: auto generate swa userId
Closes #113
1 parent a556304 commit ffcb8db

1 file changed

Lines changed: 29 additions & 14 deletions

File tree

src/public/auth.html

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,46 +84,53 @@ <h1 class="pb-4">Azure Static Web Apps Auth</h1>
8484
<option value="openid"></option>
8585
</datalist>
8686
</div>
87+
8788
<div class="form-group row">
88-
<label for="userDetails" class="col-4 col-form-label">Username</label>
89+
<label for="userId" class="col-4 col-form-label">User ID</label>
8990
<div class="col-8">
9091
<input
91-
id="userDetails"
92-
name="userDetails"
92+
disabled
93+
id="userId"
94+
name="userId"
9395
autocomplete="off"
94-
placeholder="Choose a username"
96+
placeholder="Choose a user ID"
9597
type="text"
96-
aria-describedby="userDetailsHelpBlock"
98+
aria-describedby="userIdHelpBlock"
9799
required="required"
98100
class="form-control"
99101
/>
100-
<small id="userDetailsHelpBlock" class="form-text text-muted">Username or email address of the user</small>
102+
<small id="userIdHelpBlock" class="form-text text-muted">An Azure Static Web Apps-specific unique ID for the user</small>
101103
</div>
102104
</div>
105+
103106
<div class="form-group row">
104-
<label for="userId" class="col-4 col-form-label">User ID</label>
107+
<label for="userDetails" class="col-4 col-form-label">Username</label>
105108
<div class="col-8">
106109
<input
107-
id="userId"
108-
name="userId"
110+
id="userDetails"
111+
name="userDetails"
109112
autocomplete="off"
110-
placeholder="Choose a user ID"
113+
placeholder="Choose a username"
111114
type="text"
112-
aria-describedby="userIdHelpBlock"
115+
aria-describedby="userDetailsHelpBlock"
113116
required="required"
114117
class="form-control"
115118
/>
116-
<small id="userIdHelpBlock" class="form-text text-muted">An Azure Static Web Apps-specific unique ID for the user</small>
119+
<small id="userDetailsHelpBlock" class="form-text text-muted">Username or email address of the user</small>
117120
</div>
118121
</div>
122+
119123
<div class="form-group row">
120124
<label for="userRoles" class="col-4 col-form-label">User’s roles</label>
121125
<div class="col-8">
122126
<textarea id="userRoles" name="userRoles" cols="40" rows="5" class="form-control" aria-describedby="userRolesHelpBlock"></textarea>
123-
<small id="userRolesHelpBlock" class="form-text text-muted">Roles used during authorisation. One role per line</small>
124-
<small id="userRolesHelpBlock" class="form-text text-muted">Note: roles "anonymous" and "authenticated" will be added automatically.</small>
127+
<small id="userRolesHelpBlock" class="form-text text-muted">Roles used during authorisation. One role per line.</small>
128+
<small id="userRolesHelpBlock" class="form-text text-muted"
129+
>Note: roles "authenticated" will be added automatically if not provided.</small
130+
>
125131
</div>
126132
</div>
133+
127134
<div class="form-group row">
128135
<div class="col-4"></div>
129136
<div class="col-8 text-right">
@@ -199,6 +206,9 @@ <h1 class="pb-4">Azure Static Web Apps Auth</h1>
199206
const formName = formElement.attr("name");
200207
return `${formName}@${providerName}`;
201208
}
209+
function generateUserId() {
210+
return [...Array(32)].map(() => Math.floor(Math.random() * 16).toString(16)).join("");
211+
}
202212
$.fn.saveToLocalStorage = function saveToLocalStorage(options) {
203213
const settings = $.extend({}, options);
204214

@@ -262,6 +272,10 @@ <h1 class="pb-4">Azure Static Web Apps Auth</h1>
262272
} else if (inputName === "identityProvider") {
263273
// don't restore provider name from storage.
264274
// this value will be taken from the URL
275+
} else if (inputName === "userId") {
276+
const userId = data[inputName] || generateUserId();
277+
input.val(userId);
278+
input.saveToLocalStorage();
265279
} else if (input.attr("type") !== "submit") {
266280
const value = data[inputName];
267281
input.val(value);
@@ -291,6 +305,7 @@ <h1 class="pb-4">Azure Static Web Apps Auth</h1>
291305
$("#clear").click(() => {
292306
form.find("input[type=text]:not(#identityProvider)").val("");
293307
form.find("textarea").val(defaultRoles.join("\n"));
308+
form.find("#userId").val(generateUserId());
294309
form.find("input, textarea").each((idx, element) => $(element).saveToLocalStorage());
295310
});
296311

0 commit comments

Comments
 (0)