fix(webui): handle name already being taken
Some checks failed
Build / build (pull_request) Failing after 1m1s
Some checks failed
Build / build (pull_request) Failing after 1m1s
This commit is contained in:
parent
c0ca9d9398
commit
f11277bc4b
@ -2,7 +2,7 @@ import http from "http";
|
||||
import https from "https";
|
||||
import ws from "ws";
|
||||
import { Account } from "@/src/models/loginModel";
|
||||
import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } from "@/src/services/loginService";
|
||||
import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword, isNameTaken } from "@/src/services/loginService";
|
||||
import { IDatabaseAccountJson } from "@/src/types/loginTypes";
|
||||
import { HydratedDocument } from "mongoose";
|
||||
import { logError } from "@/src/utils/logger";
|
||||
@ -105,6 +105,7 @@ const wsOnConnect = (ws: ws, req: http.IncomingMessage): void => {
|
||||
}
|
||||
} else if (data.auth.isRegister) {
|
||||
const name = await getUsernameFromEmail(data.auth.email);
|
||||
if (!(await isNameTaken(name))) {
|
||||
account = await createAccount({
|
||||
email: data.auth.email,
|
||||
password: data.auth.password,
|
||||
@ -114,6 +115,7 @@ const wsOnConnect = (ws: ws, req: http.IncomingMessage): void => {
|
||||
Nonce: createNonce()
|
||||
});
|
||||
}
|
||||
}
|
||||
if (account) {
|
||||
(ws as IWsCustomData).accountId = account.id;
|
||||
ws.send(
|
||||
|
Loading…
x
Reference in New Issue
Block a user