Next.js Discord

Discord Forum

nextauth google scopes not adding to url

Answered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
im trying to add youtube scope to my google oauth2 url but its not adding.

my route.ts:
export const authOptions: any = {
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID ?? "",
      clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "",
      authorization: `https://accounts.google.com/o/oauth2/auth/authorize?response_type=code&prompt=login`,
    }),
  ],
  authorization: {
    params: {
      prompt: "consent",
      access_type: "offline",
      response_type: "code",
      scope: "openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/youtube",
    },
  },
  session: {
    strategy: "jwt",
  },
  secret: process.env.NEXTAUTH_SECRET,
  jwt: {
    secret: process.env.NEXTAUTH_SECRET,
    maxAge: 5 * 60 * 1000,
  },
  callbacks: {
    async jwt({ token, account, profile }:any) {
      if (account) {
        token.accessToken = account.access_token
        token.id = profile.id
      }
      return token
    },
    async session({ session, token, user }:any) {
      session.accessToken = token.accessToken
      session.user.id = token.id
      
      return session
    }
  },
}
Answered by West African Lion
okay i fixed it
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID ?? "",
      clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "",
      authorization: `https://accounts.google.com/o/oauth2/auth/authorize?response_type=code&prompt=login&scope=openid%20email%20profile%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.upload`,
    }),
  ],

u have to hardcode scopes in url
View full answer

3 Replies

West African LionOP
i tried adding scopes directly into link and it works so it is problem with next auth scopes
West African LionOP
okay i fixed it
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID ?? "",
      clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "",
      authorization: `https://accounts.google.com/o/oauth2/auth/authorize?response_type=code&prompt=login&scope=openid%20email%20profile%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.upload`,
    }),
  ],

u have to hardcode scopes in url
Answer