I'm trying to override the user object that auth.js session gives you

1 Reply
bakdaddy
bakdaddy12mo ago
make a nextauth.d.ts file with something like that
import { DefaultSession, DefaultUser } from "next-auth";

interface IUser extends DefaultUser {
/**
* Role of user
*/
accessToken?: string;
}
declare module "next-auth" {
interface User extends IUser {}
interface Session {
user?: User;
}
}
import { DefaultSession, DefaultUser } from "next-auth";

interface IUser extends DefaultUser {
/**
* Role of user
*/
accessToken?: string;
}
declare module "next-auth" {
interface User extends IUser {}
interface Session {
user?: User;
}
}
it will make session.user have an optional accessToken prop or
import { DefaultSession } from "next-auth";

declare module "next-auth" {
interface Session {
accessToken?: string;
}
}
import { DefaultSession } from "next-auth";

declare module "next-auth" {
interface Session {
accessToken?: string;
}
}
for having a token on your session object somehting like that https://authjs.dev/guides/basics/role-based-access-control but for 'accessToken' instead of 'role' you could also check for profile
if(account && profile) {
...
}
if(account && profile) {
...
}