Created
August 25, 2023 09:41
-
-
Save gNaps/62429eb20fd91138c74fbe409c876cd8 to your computer and use it in GitHub Desktop.
twitch example api - [...nextauth]/route.ts
This file contains hidden or 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
| import NextAuth, { AuthOptions } from "next-auth"; | |
| export interface TwitchProfile extends Record<string, any> { | |
| sub: string | |
| preferred_username: string | |
| email: string | |
| picture: string | |
| } | |
| export default function TwitchProvider( | |
| options: any | |
| ): any { | |
| return { | |
| wellKnown: "https://id.twitch.tv/oauth2/.well-known/openid-configuration", | |
| id: "twitch", | |
| name: "Twitch", | |
| type: "oauth", | |
| authorization: { | |
| params: { | |
| scope: "openid user:read:email user:read:follows", | |
| claims: { | |
| id_token: { | |
| email: null, | |
| picture: null, | |
| preferred_username: null, | |
| }, | |
| }, | |
| }, | |
| }, | |
| idToken: true, | |
| profile(profile: any) { | |
| return { | |
| id: profile.sub, | |
| name: profile.preferred_username, | |
| email: profile.email, | |
| image: profile.picture, | |
| } | |
| }, | |
| style: { | |
| logo: "/twitch.svg", | |
| logoDark: "/twitch-dark.svg", | |
| bg: "#fff", | |
| text: "#65459B", | |
| bgDark: "#65459B", | |
| textDark: "#fff", | |
| }, | |
| options, | |
| } | |
| } | |
| export const authOptions: AuthOptions = { | |
| secret: "MXsqeQSZqvht5RE6U7Sg/EqtgKKctiyNm5qA0GoS/HM=", | |
| providers: [ | |
| TwitchProvider({ | |
| clientId: process.env.NEXT_PUBLIC_CLIENT_ID, | |
| clientSecret: process.env.NEXT_PUBLIC_CLIENT_SECRET, | |
| }), | |
| ], | |
| callbacks: { | |
| async session ({ session, token, user }) { | |
| return {...session, token } | |
| }, | |
| async jwt ({ token, user, account, profile }) { | |
| return {...token, ...account} | |
| } | |
| } | |
| }; | |
| const handler = NextAuth(authOptions) | |
| export { handler as GET, handler as POST } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment