Skip to content

Instantly share code, notes, and snippets.

@balazsorban44
Last active October 11, 2022 19:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balazsorban44/a8e6f522ebd54da2a90a588d8967fd95 to your computer and use it in GitHub Desktop.
Save balazsorban44/a8e6f522ebd54da2a90a588d8967fd95 to your computer and use it in GitHub Desktop.
//...
providers: [
Twitch({
clientId: process.env.TWITCH_ID,
clientSecret: process.env.TWITCH_SECRET,
authorization: { params: { scope: "openid user:read:email moderation:read" } },
async profile(profile, tokens) {
const id = profile.sub
const res = await fetch(`https://api.twitch.tv/helix/users?id=${id}}`, {
headers: { Authorization: `Bearer ${tokens.access_token}`, "Client-Id": process.env.TWITCH_ID },
})
const { data: [user] } = await res.json()
return {
id,
name: profile.preferred_username,
email: profile.email,
image: profile.picture,
description: user.description,
}
},
}),
],
callbacks: {
jwt({ token, user }) {
token.description ??= user.description
return token
},
session({ session, token }) {
session.user.description = token.description
return session
},
}
// ...
declare module "next-auth/jwt" {
interface JWT { description: string }
}
declare module "next-auth" {
interface User { description: string }
interface Session {user: User }
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment