mirror of https://github.com/buster-so/buster.git
error handling for auth login
This commit is contained in:
parent
cb0b7c7675
commit
6748819e39
|
@ -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"],
|
||||
|
|
|
@ -29,4 +29,4 @@
|
|||
"momentic": "^2.16.0",
|
||||
"tsx": "catalog:"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,34 +94,43 @@ 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) {
|
||||
setLastUsedMethod('email');
|
||||
await navigate({ to: redirectTo || '/app/home' });
|
||||
}
|
||||
if (data.error) {
|
||||
throw new Error(data.message);
|
||||
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' });
|
||||
},
|
||||
retry: false,
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
},
|
||||
throwOnError: true,
|
||||
});
|
||||
|
||||
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) {
|
||||
setLastUsedMethod('email');
|
||||
if (onSignUpSuccess) {
|
||||
onSignUpSuccess();
|
||||
}
|
||||
return result;
|
||||
},
|
||||
onSuccess: () => {
|
||||
setLastUsedMethod('email');
|
||||
if (onSignUpSuccess) {
|
||||
onSignUpSuccess();
|
||||
}
|
||||
},
|
||||
retry: false,
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
},
|
||||
});
|
||||
|
||||
// Combined state
|
||||
|
|
|
@ -64,12 +64,10 @@
|
|||
"packageManager": "pnpm@10.17.1",
|
||||
"pnpm": {
|
||||
"peerDependencyRules": {
|
||||
"ignoreMissing": [
|
||||
"shiki"
|
||||
],
|
||||
"ignoreMissing": ["shiki"],
|
||||
"allowedVersions": {
|
||||
"shiki": "3"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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": {}
|
||||
}
|
||||
|
|
86
turbo.json
86
turbo.json
|
@ -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",
|
||||
|
@ -181,4 +129,4 @@
|
|||
"NODE_TLS_REJECT_UNAUTHORIZED"
|
||||
],
|
||||
"envMode": "strict"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue