Skip to content

Commit

Permalink
fix: allow only alphanumeric usernames with dashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparkier committed Oct 12, 2023
1 parent 8a96dd2 commit 5e518cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions frontend/src/routes/(user)/signup/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export const actions: Actions = {
error: 'Failed to create user.'
};

if ((username as string).startsWith('-')) {
return fail(422, { ...failProps, error: 'Your username cannot start with a dash.' });
}
if ((username as string).search(/^[a-zA-Z0-9-]+$/)) {
return fail(422, {
...failProps,
error: 'Your username may only contain alphanumeric characters or dashes.'
});
}
if (!password) {
return fail(422, { ...failProps, error: 'Please enter a password.' });
}
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/routes/(user)/signup/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@
</div>
<Button type="submit" variant="raised" class="mt-5" disabled={!agreed}>Sign Up</Button>
<p class="mt-5">
Already have an account? <a href="/">Log in now!</a>
Already have an account? <a href="/" class="text-primary visited:text-primary hover:underline"
>Log in now!</a
>
</p>
{#if form?.error}
<p>{form.error}</p>
<p class="text-primary mt-4">{form.error}</p>
{/if}
</div>
</form>

0 comments on commit 5e518cb

Please sign in to comment.