forked from vercel/ai-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: simplify
next-auth
(vercel#80)
- Loading branch information
1 parent
5912336
commit 012ea40
Showing
8 changed files
with
55 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { GET, POST } from '@/auth' | ||
export const runtime = 'edge' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,35 @@ | ||
import NextAuth from 'next-auth' | ||
import NextAuth, { type DefaultSession } from 'next-auth' | ||
import GitHub from 'next-auth/providers/github' | ||
import CredentialsProvider from 'next-auth/providers/credentials' | ||
import { NextResponse } from 'next/server' | ||
|
||
// We default to using GitHub for authentication for local development and production. | ||
// On Preview deployments, we use a dummy credentials provider. This allows folks to easily | ||
// test the app without having to create a custom GitHub OAuth app or change the callback URL | ||
// just to test the application on previews. | ||
declare module 'next-auth' { | ||
interface Session { | ||
user: { | ||
/** The user's id. */ | ||
id: string | ||
} & DefaultSession['user'] | ||
} | ||
} | ||
|
||
// We have a custom /sign-in page for non-preview environments. In preview environments, the user | ||
// will be redirected to /api/auth/signin instead. | ||
export const { | ||
handlers: { GET, POST }, | ||
auth, | ||
CSRF_experimental | ||
// @ts-ignore | ||
} = NextAuth({ | ||
// @ts-ignore | ||
providers: [ | ||
process.env.VERCEL_ENV === 'preview' | ||
? CredentialsProvider({ | ||
name: 'Credentials', | ||
credentials: { | ||
username: { | ||
label: 'Username', | ||
type: 'text', | ||
placeholder: 'jsmith' | ||
}, | ||
password: { label: 'Password', type: 'password' } | ||
}, | ||
async authorize(credentials) { | ||
return { | ||
id: 1, | ||
name: 'J Smith', | ||
email: '[email protected]', | ||
picture: 'https://i.pravatar.cc/[email protected]' | ||
} as any | ||
} | ||
}) | ||
: GitHub | ||
], | ||
providers: [GitHub], | ||
callbacks: { | ||
// @ts-ignore | ||
jwt: async ({ token, profile }) => { | ||
if (profile?.id) { | ||
jwt({ token, profile }) { | ||
if (profile) { | ||
token.id = profile.id | ||
token.image = profile.picture | ||
} | ||
return token | ||
}, | ||
// @ts-ignore | ||
authorized({ auth }) { | ||
return !!auth?.user | ||
}, | ||
trustHost: true | ||
} | ||
}, | ||
...(process.env.VERCEL_ENV === 'preview' | ||
? {} | ||
: { | ||
pages: { | ||
signIn: '/sign-in' | ||
} | ||
}) | ||
pages: { | ||
signIn: '/sign-in' | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export { auth as middleware } from './auth' | ||
|
||
export const config = { | ||
matcher: ['/', '/api/chat'] | ||
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.