feat(client): refactor auth/login

Signed-off-by: Noa Virellia <noa@requiem.garden>
This commit is contained in:
2026-01-02 16:48:16 +08:00
parent a80c3cd1dd
commit 8e792ced68
10 changed files with 134 additions and 59 deletions

14
client/src/lib/random.ts Normal file
View File

@@ -0,0 +1,14 @@
/**
* Generate a cryptographically secure OAuth2 state string
* base64url encoded, URL-safe
*/
export function generateOAuthState(bytes: number = 32): string {
const random = new Uint8Array(bytes);
crypto.getRandomValues(random);
// base64url encode
return btoa(String.fromCharCode(...random))
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '');
}