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:
AbdBarho
2023-01-18 08:36:28 +01:00
committed by GitHub
4 changed files with 21 additions and 27 deletions
-7
View File
@@ -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;
},
/**
+20
View File
@@ -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;
-20
View File
@@ -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 });
}