feat: redirect user dynamically based on role instead of /protected after login
All checks were successful
Staging Build / build (push) Successful in 2m14s
All checks were successful
Staging Build / build (push) Successful in 2m14s
This commit is contained in:
@@ -32,9 +32,12 @@ export function LoginForm({
|
|||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await signIn(email, password);
|
const res = await signIn(email, password);
|
||||||
// Update this route to redirect to an authenticated route. The user already has an active session.
|
if (res.role === "admin") {
|
||||||
router.push("/protected");
|
router.push("/admin/einstellungen");
|
||||||
|
} else {
|
||||||
|
router.push("/my-customers");
|
||||||
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
setError(error instanceof Error ? error.message : "An error occurred");
|
setError(error instanceof Error ? error.message : "An error occurred");
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ export function UpdatePasswordForm({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await updatePassword(password);
|
await updatePassword(password);
|
||||||
// Update this route to redirect to an authenticated route. The user already has an active session.
|
router.push("/");
|
||||||
router.push("/protected");
|
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
setError(error instanceof Error ? error.message : "An error occurred");
|
setError(error instanceof Error ? error.message : "An error occurred");
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ export async function signIn(email: string, password: string) {
|
|||||||
|
|
||||||
// Andere aktive Sitzungen beenden
|
// Andere aktive Sitzungen beenden
|
||||||
await supabase.auth.signOut({ scope: 'others' })
|
await supabase.auth.signOut({ scope: 'others' })
|
||||||
|
|
||||||
|
return { success: true, role: userData.role }
|
||||||
}
|
}
|
||||||
|
|
||||||
return { success: true }
|
return { success: true, role: 'partner' }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function signUp(email: string, password: string) {
|
export async function signUp(email: string, password: string) {
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ export async function submitOrder(params: {
|
|||||||
console.error('PDF Generation Error:', pdfError)
|
console.error('PDF Generation Error:', pdfError)
|
||||||
}
|
}
|
||||||
|
|
||||||
revalidatePath('/protected')
|
revalidatePath('/my-customers')
|
||||||
revalidatePath('/my-orders')
|
revalidatePath('/my-orders')
|
||||||
return order as Order
|
return order as Order
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user