feature: Adds username support.

LOM eta wen
This commit is contained in:
greysoh 2024-05-05 21:56:35 -04:00
parent 9f1de2b4ec
commit 7c1e26b150
No known key found for this signature in database
GPG key ID: FE0F173B8FC01571
5 changed files with 23 additions and 5 deletions

View file

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "username" TEXT;

View file

@ -45,6 +45,7 @@ model User {
id Int @id @default(autoincrement())
email String @unique
username String? // NOT optional in the API, but just for backwards compat
name String
password String // Will be hashed using bcrypt
rootToken String?

View file

@ -17,10 +17,11 @@ export function route(routeOptions: RouteOptions) {
schema: {
body: {
type: "object",
required: ["name", "email", "password"],
required: ["name", "email", "username", "password"],
properties: {
name: { type: "string" },
username: { type: "string" },
email: { type: "string" },
password: { type: "string" },
},
@ -33,6 +34,7 @@ export function route(routeOptions: RouteOptions) {
name: string;
email: string;
password: string;
username: string;
} = req.body;
if (!options.isSignupEnabled) {
@ -60,6 +62,8 @@ export function route(routeOptions: RouteOptions) {
email: body.email,
password: saltedPassword,
username: body.username,
permissions: {
create: [] as {
permission: string;

View file

@ -15,11 +15,12 @@ export function route(routeOptions: RouteOptions) {
schema: {
body: {
type: "object",
required: ["email", "password"],
required: ["password"],
properties: {
email: { type: "string" },
password: { type: "string" },
username: { type: "string" },
password: { type: "string" }
},
},
},
@ -27,13 +28,19 @@ export function route(routeOptions: RouteOptions) {
async (req, res) => {
// @ts-ignore
const body: {
email: string;
email?: string;
username?: string;
password: string;
} = req.body;
if (!body.email && !body.username) return res.status(400).send({
error: "missing both email and username. please supply at least one."
});
const userSearch = await prisma.user.findFirst({
where: {
email: body.email,
username: body.username
},
});

View file

@ -24,6 +24,7 @@ export function route(routeOptions: RouteOptions) {
id: { type: "number" },
name: { type: "string" },
email: { type: "string" },
username: { type: "string" },
isServiceAccount: { type: "boolean" },
},
},
@ -36,6 +37,7 @@ export function route(routeOptions: RouteOptions) {
id?: number;
name?: string;
email?: string;
username?: string;
isServiceAccount?: boolean;
} = req.body;
@ -50,6 +52,7 @@ export function route(routeOptions: RouteOptions) {
id: body.id,
name: body.name,
email: body.email,
username: body.username,
isRootServiceAccount: body.isServiceAccount,
},
});
@ -60,6 +63,7 @@ export function route(routeOptions: RouteOptions) {
name: i.name,
email: i.email,
isServiceAccount: i.isRootServiceAccount,
username: i.username
})),
};
},