You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You don't need a repo to "reproduce" this issue, just add the @side-base/nuxt-auth model with "auth.js" as it provider then try to extend the callback parameters type using "declare module".
Just in case below is my "minimal" config in the completely new Nuxt 3 project.
NuxtAuthHandler files, you can ignore almost all of it, just focus on the callback code:
importCredentialsProviderfrom'next-auth/providers/credentials';import{NuxtAuthHandler}from'#auth';interfaceCustomUser{id: string;username: string;password: string;}exportdefaultNuxtAuthHandler({// A secret string you define, to ensure correct encryptionsecret: 'C4A01200-A1C5-47F5-A392-3F693B973489',providers: [// @ts-expect-error Use .default here for it to work during SSR.CredentialsProvider.default({id: 'credentials',name: 'Credentials',credentials: {username: {label: 'Username',type: 'text',placeholder: 'Username'},password: {label: 'Password',type: 'password',placeholder: 'Password',},},asyncauthorize(credentials: {username: string;password: string}){// Add logic here to look up the user from the credentials suppliedconsole.log(`=======================================`);console.log(`Authorized credentials:`);console.log(JSON.stringify(credentials));console.log(`=======================================`);constuser={id: crypto.randomUUID(),username: credentials.username,// password: credentials.password,};console.log(`Credentials: ${JSON.stringify(user)}`);if(credentials.username&&credentials.password){// Any object returned will be saved in `user` property of the JWTreturnuser;}else{// If you return null then an error will be displayed advising the user to check their details.returnnull;// You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter}},}),],// Callbacks should be here at the root levelcallbacks: {asyncsignIn({ user, account, profile, email, credentials }){console.log(`------------------ BEFORE SIGN IN -------------------`);console.log(user);console.log(`------------------ BEFORE SIGN IN -------------------`);returntrue;},asyncjwt({ token, user, account, profile, isNewUser }){console.log(`------------------JWT-------------------`);console.log('JWT Callback - Input token:',token);console.log('JWT Callback - Input user:',user);console.log(`------------------JWT-------------------`);if(user){return{
...token,userData: {// Store user data in a dedicated propertyid: user.id,username: user.username,},};}returntoken;},asyncsession({ session, user, token }){console.log('Session Callback - Input session:',session);console.log('Session Callback - Input token:',token);// Make sure user data is copied to sessionif(token.userData){session.user=token.userData;}console.log('Session Callback - Returning session:',session);returnsession;},asyncredirect({ url, baseUrl }){console.log(`------------------ REDIRECT URL -------------------`);console.log(url);console.log(baseUrl);console.log(`---------------------------------------------------`);returnurl;},},});
This part for more specific
if(user){return{
...token,userData: {// Store user data in a dedicated propertyid: user.id,username: user.username,<----------------THISISWHERETHEISSUEHAPPEN},};}
TypeScript: Cannot extend User type despite it being declared and visible in IDE and the official docs don't have any "section" on when using with TypeScript but the original package Auth.jshave
I did describe this issue detailed in the Reproduction sections so I will not repeat it here.
I will be very appreciated, If anyone have same issue or have a solutions to this issue, please add a comment.
To this package dev teams, please add a document about TypeScript usage.
Additional context
No response
Logs
The text was updated successfully, but these errors were encountered:
Environment
Reproduction
You don't need a repo to "reproduce" this issue, just add the @side-base/nuxt-auth model with "auth.js" as it provider then try to extend the callback parameters type using "declare module".
Just in case below is my "minimal" config in the completely new Nuxt 3 project.
nuxt.config.ts
fileNuxtAuthHandler
files, you can ignore almost all of it, just focus on thecallback
code:This part for more specific
The
user.username
got the below error:But I did extend that
User
interface/types like this:And if I click to the
User
type when hover my mouse to theuser
I got property type as below:Describe the bug
TypeScript: Cannot extend
User
type despite it being declared and visible in IDE and the official docs don't have any "section" on when using withTypeScript
but the original packageAuth.js
haveI did describe this issue detailed in the
Reproduction
sections so I will not repeat it here.I will be very appreciated, If anyone have same issue or have a solutions to this issue, please add a comment.
To this
package
dev teams, please add a document about TypeScript usage.Additional context
No response
Logs
The text was updated successfully, but these errors were encountered: