Refactor to use ai/rsc (#253)
This commit is contained in:
parent
69ca8fcc22
commit
e85ba803dd
66 changed files with 2799 additions and 740 deletions
42
auth.config.ts
Normal file
42
auth.config.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import type { NextAuthConfig } from 'next-auth'
|
||||
|
||||
export const authConfig = {
|
||||
secret: process.env.AUTH_SECRET,
|
||||
pages: {
|
||||
signIn: '/login',
|
||||
newUser: '/signup'
|
||||
},
|
||||
callbacks: {
|
||||
async authorized({ auth, request: { nextUrl } }) {
|
||||
const isLoggedIn = !!auth?.user
|
||||
const isOnLoginPage = nextUrl.pathname.startsWith('/login')
|
||||
const isOnSignupPage = nextUrl.pathname.startsWith('/signup')
|
||||
|
||||
if (isLoggedIn) {
|
||||
if (isOnLoginPage || isOnSignupPage) {
|
||||
return Response.redirect(new URL('/', nextUrl))
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
async jwt({ token, user }) {
|
||||
if (user) {
|
||||
token = { ...token, id: user.id }
|
||||
}
|
||||
|
||||
return token
|
||||
},
|
||||
async session({ session, token }) {
|
||||
if (token) {
|
||||
const { id } = token as { id: string }
|
||||
const { user } = session
|
||||
|
||||
session = { ...session, user: { ...user, id } }
|
||||
}
|
||||
|
||||
return session
|
||||
}
|
||||
},
|
||||
providers: []
|
||||
} satisfies NextAuthConfig
|
||||
Loading…
Add table
Add a link
Reference in a new issue