Connect, collaborate, and grow with a community of TypeScript developers
fix: redirects on auth actions (#339)
Ernesto Resendebb8aad090ebc
diff --git a/src/components/ui/navigation.tsx b/src/components/ui/navigation.tsxindex 69b92800..90f4d190 100644--- a/src/components/ui/navigation.tsx+++ b/src/components/ui/navigation.tsx@@ -131,7 +131,6 @@ function LoginButton() {};const handleSignOut = async () => {await signOut({ redirect: false });- router.push('/');};return session ? (diff --git a/src/server/auth.ts b/src/server/auth.tsindex 077db316..7df301e0 100644--- a/src/server/auth.ts+++ b/src/server/auth.ts@@ -27,6 +27,11 @@ declare module 'next-auth' {export const authOptions: NextAuthOptions = {callbacks: {+ redirect: async ({ url, baseUrl }) => {+ if (url.startsWith('/')) return `${baseUrl}${url}`;+ else if (new URL(url).origin === baseUrl) return url;+ return baseUrl;+ },session: async ({ session, user }) => {// 1. Statelet userRoles: RoleTypes[] = [];