diff --git a/website/cypress/e2e/auth/signin.cy.ts b/website/cypress/e2e/auth/signin.cy.ts index 6d57d1f9..2a651f1f 100644 --- a/website/cypress/e2e/auth/signin.cy.ts +++ b/website/cypress/e2e/auth/signin.cy.ts @@ -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 {}; diff --git a/website/src/pages/api/auth/[...nextauth].ts b/website/src/pages/api/auth/[...nextauth].ts index c718ddce..3d3dbaa4 100644 --- a/website/src/pages/api/auth/[...nextauth].ts +++ b/website/src/pages/api/auth/[...nextauth].ts @@ -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; }, /** diff --git a/website/src/pages/api/username.ts b/website/src/pages/api/username.ts new file mode 100644 index 00000000..ba71c4b5 --- /dev/null +++ b/website/src/pages/api/username.ts @@ -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; diff --git a/website/src/pages/api/username.tsx b/website/src/pages/api/username.tsx deleted file mode 100644 index 6cf362c2..00000000 --- a/website/src/pages/api/username.tsx +++ /dev/null @@ -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 }); -}