How can I modify the "User" scheme in NextAuth?
Unanswered
Cinnamon posted this in #help-forum
CinnamonOP
Hi, I'm making a simple website with a Microsoft login option, but I don't want to store sensitive data, just in case. How can I remove certain values of the User scheme? (for exemple the first and second name of the user).
Currently, this is my code for auth.ts (nextauth)
Currently, this is my code for auth.ts (nextauth)
import AzureADProvider from "next-auth/providers/azure-ad"
import { MongoDBAdapter } from "@auth/mongodb-adapter"
import clientPromise from "@/lib/mongodb"
import NextAuth from "next-auth/next"
import { getMinecraftProfile } from "@/lib/minecraft"
export const authOptions = {
adapter: MongoDBAdapter(clientPromise) as any,
secret: process.env.NEXTAUTH_SECRET,
providers: [
AzureADProvider({
clientId: process.env.AZURE_AD_CLIENT_ID as string,
clientSecret: process.env.AZURE_AD_CLIENT_SECRET as string,
tenantId: process.env.AZURE_AD_TENANT_ID,
httpOptions: { timeout: 10000 },
authorization: { params: { scope: "openid offline_access profile email XboxLive.signin Xboxlive.offline_access" } },
})
],
callbacks: {
session: async ({ session, token }) => {
if (session?.user) {
session.user.id = token.uid;
}
return session;
},
jwt: async ({ token, user, account }) => {
if (user) {
token.uid = user.id;
}
console.log(account)
const profile = await getMinecraftProfile(account.access_token)
console.log(profile)
return token;
},
},
session: {
strategy: 'jwt',
},
}
export default NextAuth(authOptions)9 Replies
CinnamonOP
The user currently looks like this and I want to remove the name key
European sprat
What are you logging there
CinnamonOP
I use the MongoAdapter for NextAuth
I log the Accounts, Users, and sessions
European sprat
I don't really know how next auth works but when there's something I want to remove a value from, I'll destructure the object and only return what I want. Maybe in one of these steps you can do that
@European sprat I don't really know how next auth works but when there's something I want to remove a value from, I'll destructure the object and only return what I want. Maybe in one of these steps you can do that
CinnamonOP
i don't really know how that would work... can you show me a little code example?
European sprat
I don't use next auth
Its just a general concept. If there's a place where the user values are saved, maybe you can choose what values to save before it returns
CinnamonOP
Yes I looked into the code but it’s minified and very hard to read