Refactor to use ai/rsc (#253)

This commit is contained in:
Jeremy 2024-03-14 20:00:52 +03:00 committed by GitHub
parent 69ca8fcc22
commit e85ba803dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 2799 additions and 740 deletions

42
auth.config.ts Normal file
View 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