's'
This commit is contained in:
52
lib/auth.ts
Normal file
52
lib/auth.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import NextAuth from 'next-auth'
|
||||
import GithubProvider from 'next-auth/providers/github'
|
||||
import type { DefaultSession, NextAuthConfig } from 'next-auth'
|
||||
|
||||
declare module 'next-auth' {
|
||||
interface Session {
|
||||
user: {
|
||||
accessToken?: string
|
||||
} & DefaultSession['user']
|
||||
}
|
||||
interface JWT {
|
||||
accessToken?: string
|
||||
}
|
||||
interface User {
|
||||
accessToken?: string
|
||||
}
|
||||
}
|
||||
|
||||
const config = {
|
||||
providers: [
|
||||
GithubProvider({
|
||||
clientId: process.env.GITHUB_CLIENT_ID!,
|
||||
clientSecret: process.env.GITHUB_SECRET!,
|
||||
authorization: {
|
||||
params: { scope: 'repo' }
|
||||
}
|
||||
})
|
||||
],
|
||||
callbacks: {
|
||||
async jwt({ token, account }) {
|
||||
if (account?.access_token) {
|
||||
token.accessToken = account.access_token
|
||||
}
|
||||
return token
|
||||
},
|
||||
async session({ session, token }) {
|
||||
if (session?.user) {
|
||||
session.user.accessToken = token.accessToken as string
|
||||
}
|
||||
return session
|
||||
}
|
||||
},
|
||||
pages: {
|
||||
signIn: '/auth/signin'
|
||||
},
|
||||
secret: process.env.GITHUB_SECRET
|
||||
} satisfies NextAuthConfig
|
||||
|
||||
const handler = NextAuth(config)
|
||||
|
||||
export const auth = handler.auth
|
||||
export const { handlers: { GET, POST } } = handler
|
||||
Reference in New Issue
Block a user