error handling for auth login

This commit is contained in:
Nate Kelley 2025-09-23 21:06:40 -06:00
parent cb0b7c7675
commit 6748819e39
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
10 changed files with 62 additions and 145 deletions

View File

@ -5,12 +5,7 @@
"build": {
"dependsOn": ["@buster/database#build"],
"outputs": ["target/release/**"],
"inputs": [
"server/**/*",
"libs/**/*",
"Cargo.toml",
"Cargo.lock"
]
"inputs": ["server/**/*", "libs/**/*", "Cargo.toml", "Cargo.lock"]
},
"start": {
"dependsOn": ["@buster/database#start", "build"],

View File

@ -19,14 +19,23 @@ export const useOAuthMutation = (
setLastUsedMethod: (method: SignInTypes) => void
) => {
return useMutation({
mutationFn,
mutationFn: async () => {
const result = await mutationFn();
if (!result.success) {
throw new Error(result.error || `${type} authentication failed`);
}
return result;
},
onSuccess: (data) => {
if (data.success && data.url) {
setLastUsedMethod(type);
window.location.href = data.url;
}
},
throwOnError: true,
retry: false,
onError: (error) => {
console.error(error);
},
});
};
@ -85,33 +94,42 @@ export const useAuthMutations = (redirectTo?: string | null, onSignUpSuccess?: (
// Email/Password Mutations
const emailSignInMutation = useMutation({
mutationFn: ({ email, password }: { email: string; password: string }) =>
signInWithEmailAndPassword({ data: { email, password, redirectUrl: redirectTo } }),
onSuccess: async (data) => {
if (!data.error) {
mutationFn: async ({ email, password }: { email: string; password: string }) => {
const result = await signInWithEmailAndPassword({
data: { email, password, redirectUrl: redirectTo },
});
if (result.error) {
throw new Error(result.message);
}
return result;
},
onSuccess: async () => {
setLastUsedMethod('email');
await navigate({ to: redirectTo || '/app/home' });
}
if (data.error) {
throw new Error(data.message);
}
},
throwOnError: true,
retry: false,
onError: (error) => {
console.error(error);
},
});
const emailSignUpMutation = useMutation({
mutationFn: ({ email, password }: { email: string; password: string }) =>
signUpWithEmailAndPassword({ data: { email, password, redirectTo } }),
onSuccess: (data) => {
if (data.error) {
throw new Error(data.error);
mutationFn: async ({ email, password }: { email: string; password: string }) => {
const result = await signUpWithEmailAndPassword({ data: { email, password, redirectTo } });
if (!result.success) {
throw new Error(result.error || 'Sign up failed');
}
if (data.success) {
return result;
},
onSuccess: () => {
setLastUsedMethod('email');
if (onSignUpSuccess) {
onSignUpSuccess();
}
}
},
retry: false,
onError: (error) => {
console.error(error);
},
});

View File

@ -64,9 +64,7 @@
"packageManager": "pnpm@10.17.1",
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": [
"shiki"
],
"ignoreMissing": ["shiki"],
"allowedVersions": {
"shiki": "3"
}

View File

@ -16,8 +16,6 @@
"prebuild": "[ \"$SKIP_ENV_CHECK\" = \"true\" ] || tsx scripts/validate-env.ts",
"build": "tsc",
"build:dry-run": "tsc",
"build:commonjs": "tsc --module commonjs --moduleResolution node",
"build:commonjs:watch": "npm run build:commonjs && tsc --module commonjs --moduleResolution node --watch",
"dev": "tsc --watch",
"dev:fast": "tsc --watch",
"lint": "biome check --write",

View File

@ -2,17 +2,6 @@
"$schema": "https://turborepo.com/schema.json",
"extends": ["//"],
"tasks": {
"build:commonjs": {
"cache": false,
"persistent": false,
"dependsOn": ["@buster/database#build:commonjs"],
"outputs": ["dist/**"]
},
"build:commonjs:watch": {
"cache": false,
"persistent": true,
"dependsOn": ["build:commonjs"]
},
"dev": {
"cache": false,
"persistent": true,

View File

@ -2,22 +2,6 @@
"$schema": "https://turbo.build/schema.json",
"extends": ["//"],
"tasks": {
"dev:mastra": {
"cache": false,
"persistent": true,
"dependsOn": [
"@buster/database#build:commonjs",
"@buster/access-controls#build:commonjs",
"@buster/data-source#build:commonjs",
"@buster/search#build:commonjs"
],
"with": [
"@buster/database#build:commonjs:watch",
"@buster/access-controls#build:commonjs:watch",
"@buster/data-source#build:commonjs:watch",
"@buster/search#build:commonjs:watch"
]
},
"dev": {
"cache": false,
"persistent": true,

View File

@ -16,8 +16,6 @@
"prebuild": "[ \"$SKIP_ENV_CHECK\" = \"true\" ] || tsx scripts/validate-env.ts",
"build": "tsc",
"build:dry-run": "tsc",
"build:commonjs": "tsc --module commonjs --moduleResolution node",
"build:commonjs:watch": "npm run build:commonjs && tsc --module commonjs --moduleResolution node --watch",
"lint": "biome check --write",
"lint:fix": "biome check --write",
"test": "vitest run",

View File

@ -1,16 +1,5 @@
{
"$schema": "https://turborepo.com/schema.json",
"extends": ["//"],
"tasks": {
"build:commonjs": {
"cache": false,
"persistent": false,
"outputs": ["dist/**"]
},
"build:commonjs:watch": {
"cache": false,
"persistent": true,
"dependsOn": ["build:commonjs"]
}
}
"tasks": {}
}

View File

@ -4,25 +4,13 @@
"concurrency": "20",
"tasks": {
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"dist/**",
".next/**"
]
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"build:dry-run": {
"dependsOn": [
"^build:dry-run"
],
"outputs": [
"dist/**",
".next/**"
],
"env": [
"SKIP_ENV_CHECK"
]
"dependsOn": ["^build:dry-run"],
"outputs": ["dist/**", ".next/**"],
"env": ["SKIP_ENV_CHECK"]
},
"dev": {
"cache": false,
@ -37,29 +25,19 @@
"persistent": true
},
"lint": {
"dependsOn": [
"^lint"
]
"dependsOn": ["^lint"]
},
"typecheck": {
"dependsOn": [
"^build"
]
"dependsOn": ["^build"]
},
"test": {
"dependsOn": [
"^build"
]
"dependsOn": ["^build"]
},
"test:unit": {
"dependsOn": [
"^test:unit"
]
"dependsOn": ["^test:unit"]
},
"test:integration": {
"dependsOn": [
"^build"
]
"dependsOn": ["^build"]
},
"test:watch": {
"cache": false,
@ -74,53 +52,23 @@
"persistent": true
},
"test:coverage": {
"dependsOn": [
"^build"
],
"outputs": [
"coverage/**"
]
},
"build:commonjs": {
"cache": false,
"persistent": false,
"outputs": [
"dist/**"
]
},
"build:commonjs:watch": {
"cache": false,
"persistent": true,
"dependsOn": [
"build:commonjs"
]
"dependsOn": ["^build"],
"outputs": ["coverage/**"]
},
"db:migrate": {
"cache": false,
"env": [
"NODE_TLS_REJECT_UNAUTHORIZED"
]
"cache": false
},
"db:seed": {
"cache": false,
"env": [
"DATABASE_URL",
"ENVIRONMENT",
"NODE_ENV"
]
"cache": false
},
"db:init": {
"cache": false,
"dependsOn": ["db:migrate"],
"env": [
"DATABASE_URL",
"ENVIRONMENT",
"NODE_ENV"
]
"dependsOn": ["db:migrate"]
}
},
"globalEnv": [
"NODE_ENV",
"NODE_TLS_REJECT_UNAUTHORIZED",
"CI",
"VERCEL",
"VERCEL_ENV",