feat(auth): add sign up flow with email domain validation and password confirm

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
christian.vidal
2026-03-27 17:54:31 +01:00
co-authored by Claude Sonnet 4.6
parent c1f809dfdb
commit b88ca57c95
2 changed files with 104 additions and 10 deletions
+20
View File
@@ -8,6 +8,26 @@ export interface AuthSession {
user: { id: string; email: string };
}
export async function signUp(email: string, password: string): Promise<void> {
if (!email.toLowerCase().endsWith(ALLOWED_DOMAIN)) {
throw new Error(`Only ${ALLOWED_DOMAIN} email addresses are allowed.`);
}
const response = await fetch(`${SUPABASE_URL}/auth/v1/signup`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apikey': SUPABASE_ANON_KEY,
},
body: JSON.stringify({ email, password }),
});
if (!response.ok) {
const err = await response.json().catch(() => ({}));
throw new Error(err.error_description || err.message || 'Registration failed.');
}
}
export async function signIn(email: string, password: string): Promise<AuthSession> {
if (!email.toLowerCase().endsWith(ALLOWED_DOMAIN)) {
throw new Error(`Only ${ALLOWED_DOMAIN} email addresses are allowed.`);