Home > Back-end >  Next-Auth Profile custom typings
Next-Auth Profile custom typings

Time:10-23

I'm having a problem with typescript and Next Auth type definitions. According to the docs I should be able to add my custom types to the NextAuth modules and so I did for the Profile interface in the next-auth.d.ts. It does add the type when I do profile.groups but when I want to destructure it typescript complains that this type doesn't exists on Profile type... Any idea what I'm missing?

enter image description here

enter image description here

enter image description here

CodePudding user response:

This has to do with the fact that you can't destructure undefined in JS/TS.

As you might have noticed, profile parameter can be undefined. Since this variable can take the undefined value, typescript does not want to see it as "destructurable" because it can not destructure undefined value.

You could try to check for undefined first and then cast the profile as Profile instead of Profile | undefined.

  • Related