feature: Adds username support.
LOM eta wen
This commit is contained in:
parent
9f1de2b4ec
commit
7c1e26b150
5 changed files with 23 additions and 5 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "User" ADD COLUMN "username" TEXT;
|
|
@ -45,6 +45,7 @@ model User {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
|
|
||||||
email String @unique
|
email String @unique
|
||||||
|
username String? // NOT optional in the API, but just for backwards compat
|
||||||
name String
|
name String
|
||||||
password String // Will be hashed using bcrypt
|
password String // Will be hashed using bcrypt
|
||||||
rootToken String?
|
rootToken String?
|
||||||
|
|
|
@ -17,10 +17,11 @@ export function route(routeOptions: RouteOptions) {
|
||||||
schema: {
|
schema: {
|
||||||
body: {
|
body: {
|
||||||
type: "object",
|
type: "object",
|
||||||
required: ["name", "email", "password"],
|
required: ["name", "email", "username", "password"],
|
||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
name: { type: "string" },
|
name: { type: "string" },
|
||||||
|
username: { type: "string" },
|
||||||
email: { type: "string" },
|
email: { type: "string" },
|
||||||
password: { type: "string" },
|
password: { type: "string" },
|
||||||
},
|
},
|
||||||
|
@ -33,6 +34,7 @@ export function route(routeOptions: RouteOptions) {
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
email: string;
|
||||||
password: string;
|
password: string;
|
||||||
|
username: string;
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
if (!options.isSignupEnabled) {
|
if (!options.isSignupEnabled) {
|
||||||
|
@ -60,6 +62,8 @@ export function route(routeOptions: RouteOptions) {
|
||||||
email: body.email,
|
email: body.email,
|
||||||
password: saltedPassword,
|
password: saltedPassword,
|
||||||
|
|
||||||
|
username: body.username,
|
||||||
|
|
||||||
permissions: {
|
permissions: {
|
||||||
create: [] as {
|
create: [] as {
|
||||||
permission: string;
|
permission: string;
|
||||||
|
|
|
@ -15,11 +15,12 @@ export function route(routeOptions: RouteOptions) {
|
||||||
schema: {
|
schema: {
|
||||||
body: {
|
body: {
|
||||||
type: "object",
|
type: "object",
|
||||||
required: ["email", "password"],
|
required: ["password"],
|
||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
email: { type: "string" },
|
email: { type: "string" },
|
||||||
password: { type: "string" },
|
username: { type: "string" },
|
||||||
|
password: { type: "string" }
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -27,13 +28,19 @@ export function route(routeOptions: RouteOptions) {
|
||||||
async (req, res) => {
|
async (req, res) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const body: {
|
const body: {
|
||||||
email: string;
|
email?: string;
|
||||||
|
username?: string;
|
||||||
password: string;
|
password: string;
|
||||||
} = req.body;
|
} = 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({
|
const userSearch = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
email: body.email,
|
email: body.email,
|
||||||
|
username: body.username
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ export function route(routeOptions: RouteOptions) {
|
||||||
id: { type: "number" },
|
id: { type: "number" },
|
||||||
name: { type: "string" },
|
name: { type: "string" },
|
||||||
email: { type: "string" },
|
email: { type: "string" },
|
||||||
|
username: { type: "string" },
|
||||||
isServiceAccount: { type: "boolean" },
|
isServiceAccount: { type: "boolean" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -36,6 +37,7 @@ export function route(routeOptions: RouteOptions) {
|
||||||
id?: number;
|
id?: number;
|
||||||
name?: string;
|
name?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
|
username?: string;
|
||||||
isServiceAccount?: boolean;
|
isServiceAccount?: boolean;
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
|
@ -50,6 +52,7 @@ export function route(routeOptions: RouteOptions) {
|
||||||
id: body.id,
|
id: body.id,
|
||||||
name: body.name,
|
name: body.name,
|
||||||
email: body.email,
|
email: body.email,
|
||||||
|
username: body.username,
|
||||||
isRootServiceAccount: body.isServiceAccount,
|
isRootServiceAccount: body.isServiceAccount,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -60,6 +63,7 @@ export function route(routeOptions: RouteOptions) {
|
||||||
name: i.name,
|
name: i.name,
|
||||||
email: i.email,
|
email: i.email,
|
||||||
isServiceAccount: i.isRootServiceAccount,
|
isServiceAccount: i.isRootServiceAccount,
|
||||||
|
username: i.username
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue