feat(auth): improve error handling for invalid credentials on login, redirect to workspace on successful social login

This commit is contained in:
Waleed Latif
2025-02-17 14:52:16 -08:00
parent 6f0a29675f
commit b5b8f55457
2 changed files with 12 additions and 1 deletions
+10 -1
View File
@@ -33,7 +33,12 @@ export default function LoginPage() {
const password = formData.get('password') as string
try {
await client.signIn.email({ email, password })
const result = await client.signIn.email({ email, password })
if (!result || result.error) {
throw new Error(result?.error?.message || 'Authentication failed')
}
router.push('/w/1')
} catch (err: any) {
let errorMessage = 'Invalid email or password'
@@ -56,6 +61,8 @@ export default function LoginPage() {
}
addNotification('error', errorMessage, null)
// Prevent navigation on error
return
} finally {
setIsLoading(false)
}
@@ -64,6 +71,7 @@ export default function LoginPage() {
async function signInWithGithub() {
try {
await client.signIn.social({ provider: 'github' })
router.push('/w/1')
} catch (err: any) {
let errorMessage = 'Failed to sign in with GitHub'
@@ -83,6 +91,7 @@ export default function LoginPage() {
async function signInWithGoogle() {
try {
await client.signIn.social({ provider: 'google' })
router.push('/w/1')
} catch (err: any) {
let errorMessage = 'Failed to sign in with Google'
+2
View File
@@ -30,6 +30,8 @@ export const auth = betterAuth({
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
throwOnMissingCredentials: true,
throwOnInvalidCredentials: true,
sendResetPassword: async ({ user, url, token }, request) => {
const result = await resend.emails.send({
from: 'Sim Studio <team@simstudio.ai>',