diff --git a/src/app/page.tsx b/src/app/page.tsx index 7bcd29e..a86e576 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,3 +1,9 @@ -export default function Home() { - return
; +import { auth } from '@/auth'; +import { redirect } from 'next/navigation'; + +export default async function Home() { + const session = await auth(); + + if (!session?.user) redirect('/login'); + else redirect('/home'); } diff --git a/src/auth.ts b/src/auth.ts index 50b654c..b3ed869 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -7,7 +7,10 @@ export const { handlers, signIn, signOut, auth } = NextAuth({ ), callbacks: { authorized: async ({ auth }) => { - return !!auth; + return !!auth?.user; }, }, + pages: { + signIn: '/login', + }, }); diff --git a/src/middleware.ts b/src/middleware.ts index 175bedc..345d04d 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,18 +1,4 @@ -import { auth } from '@/auth'; - -export default auth((req) => { - if ( - !req.auth && - req.nextUrl.pathname !== '/login' && - process.env.MEETUP_SKIP_LOGIN !== 'true' - ) { - const newUrl = new URL('/login', req.nextUrl.origin); - return Response.redirect(newUrl); - } else if (req.auth != null && req.nextUrl.pathname === '/') { - const newUrl = new URL('/home', req.nextUrl.origin); - return Response.redirect(newUrl); - } -}); +export { auth as middleware } from '@/auth'; export const config = { matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],