Next.js Discord

Discord Forum

Is NextAuth GoogleProvider profile callback always when authenticating or only once ?

Unanswered
Cuckoo wasp posted this in #help-forum
Open in Discord
Cuckoo waspOP
I have CredentialProvider and GoogleProvider in my project. Whenever the user authenticates with GoogleProvider I want to create a random username and password in profile callback:
        profile(profile) {
          console.log(profile)
          const name = profile.given_name + ' ' + profile.family_name
          return {
            id: profile.id,
            email: profile.email,
            image: profile.picture,
            name,
            username: randomUsername(),
            password: randomEncPass(),
          }

     }


I want to know if profile callback is only called once when the user first uses it to login or it's always called whenever the user authenticates via Google? In later case, I would end up with random usernames on every authentication.

2 Replies

IIRC profile is part of another event. You shouldn't be using it set profile data
You'll need to store the name inside the database if it doesn't exist instead to persist it