mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-16 11:14:44 +08:00
Cleaning up the username api route and ensuring the users name is fresh
This commit is contained in:
@@ -88,16 +88,17 @@ export const authOptions: AuthOptions = {
|
||||
* Ensure we propagate the user's role when creating the session from the
|
||||
* token.
|
||||
*/
|
||||
async session({ session, token }) {
|
||||
async session({ session, user, token }) {
|
||||
session.user.role = token.role;
|
||||
session.user.isNew = token.isNew;
|
||||
session.user.name = token.name;
|
||||
return session;
|
||||
},
|
||||
/**
|
||||
* When creating a token, fetch the user's role and inject it in the token.
|
||||
* This let's use forward the role to the session object.
|
||||
*/
|
||||
async jwt({ token }) {
|
||||
async jwt({ token, user, account }) {
|
||||
const { isNew, name, role } = await prisma.user.findUnique({
|
||||
where: { id: token.sub },
|
||||
select: { name: true, role: true, isNew: true },
|
||||
|
||||
Reference in New Issue
Block a user