im using next-auth 5.0.0-beta.15 for my authentication
i tried just returning the user through credentials, i tried making some changes to the auth.config.ts file but nothing worked
auth.ts
//imports and other functons
export const { auth, signIn, signOut } = NextAuth({
...authConfig,
providers: [Credentials({
async authorize(credentials) {
const parsedCredentials = z
.object({ email: z.string().email(), password: z.string().min(6) ,userType: z.string()})
.safeParse(credentials);
if (parsedCredentials.success) {
try{
const user = await getUser(parsedCredentials.data);
if (!user) return null;
return user;
}
catch(error){
//catch error
}
}
return null;
},
}),
],
});
auth.config.ts
import type { NextAuthConfig } from 'next-auth';
export const authConfig = {
trustHost: true,
pages: {
signIn: '/login',
},
callbacks: {
authorized({ auth, request: { nextUrl } }) {
const isLoggedIn = !!auth?.user;
const isOnDashboard = nextUrl.pathname.startsWith('/dashboard');
if (isOnDashboard) {
if (isLoggedIn) return true;
return false; // Redirect unauthenticated users to login page
} else if (isLoggedIn) {
return Response.redirect(new URL('/dashboard', nextUrl));
}
return true;
},
},
providers: [], // Add providers with an empty array for now
} satisfies NextAuthConfig;
i want next auth to create a session where all the data i bgring form the backend is stored as session, currently the stored session is from
node_modules > @auth > core > src > Types
export interface DefaultSession {
user?: User
expires: ISODateString }
export interface Session extends DefaultSession {}
export interface User {
id?: string
name?: string | null
email?: string | null
image?: string | null
}
'''
the user i get is
user: { name: ‘student 0’, email: ‘[email protected]’ },
expires: ‘2024-05-26T04:22:12.637Z’
}
the user i want to get is
user: {
id: ‘023’,
name: ‘student 0’,
email: ‘[email protected]’,
userName: ‘3f828b661d8d’,
emailVerified: undefined,
phoneNumber: undefined,
role: ‘STUDENT’
}
i have tried directly changing this interface but nothing happened, im using "next": "^14.1.3", the auth files are at the root directors of the projeact and customers and employes
Arch Cion is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.