mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-30 11:50:06 +08:00
Merge pull request #819 from LAION-AI/797-udpate-username-web
Cleaning up the username api route and ensuring the users name is fresh
This commit is contained in:
@@ -27,13 +27,6 @@ describe("signin flow", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
it("shows the logged in users email address if logged in with email", () => {
|
||||
const emailAddress = "user@example.com";
|
||||
cy.signInWithEmail(emailAddress);
|
||||
// The user will only see the email address if the window is wide enough, not technically required as even when hidden this will find it in the page.
|
||||
cy.viewport(1920, 1000);
|
||||
cy.contains('[data-cy="username"]', emailAddress);
|
||||
});
|
||||
});
|
||||
|
||||
export {};
|
||||
|
||||
@@ -91,6 +91,7 @@ export const authOptions: AuthOptions = {
|
||||
async session({ session, token }) {
|
||||
session.user.role = token.role;
|
||||
session.user.isNew = token.isNew;
|
||||
session.user.name = token.name;
|
||||
return session;
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { withoutRole } from "src/lib/auth";
|
||||
import prisma from "src/lib/prismadb";
|
||||
|
||||
/**
|
||||
* Updates the user's `name` field in the `User` table.
|
||||
*/
|
||||
const handler = withoutRole("banned", async (req, res, token) => {
|
||||
const { username } = req.body;
|
||||
const { name } = await prisma.user.update({
|
||||
where: {
|
||||
id: token.sub,
|
||||
},
|
||||
data: {
|
||||
name: username,
|
||||
},
|
||||
});
|
||||
res.json({ name });
|
||||
});
|
||||
|
||||
export default handler;
|
||||
@@ -1,20 +0,0 @@
|
||||
import { getSession } from "next-auth/react";
|
||||
import prisma from "src/lib/prismadb";
|
||||
|
||||
// POST /api/post
|
||||
// Required fields in body: title
|
||||
// Optional fields in body: content
|
||||
export default async function handle(req, res) {
|
||||
const { username } = req.body;
|
||||
|
||||
const session = await getSession({ req });
|
||||
const result = await prisma.user.update({
|
||||
where: {
|
||||
email: session.user.email,
|
||||
},
|
||||
data: {
|
||||
name: username,
|
||||
},
|
||||
});
|
||||
res.json({ name: result.name });
|
||||
}
|
||||
Reference in New Issue
Block a user