fix: getUsernameFromEmail returning wrong value (#2538)
Closes #2537 Reviewed-on: #2538 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
c0a0463a68
commit
a2a441ecb0
@ -32,7 +32,7 @@ export const getUsernameFromEmail = async (email: string): Promise<string> => {
|
|||||||
name = nameFromEmail + suffix;
|
name = nameFromEmail + suffix;
|
||||||
} while (await isNameTaken(name));
|
} while (await isNameTaken(name));
|
||||||
}
|
}
|
||||||
return nameFromEmail;
|
return name;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createAccount = async (accountData: IDatabaseAccountRequiredFields): Promise<IDatabaseAccountJson> => {
|
export const createAccount = async (accountData: IDatabaseAccountRequiredFields): Promise<IDatabaseAccountJson> => {
|
||||||
|
@ -2,13 +2,7 @@ import http from "http";
|
|||||||
import https from "https";
|
import https from "https";
|
||||||
import ws from "ws";
|
import ws from "ws";
|
||||||
import { Account } from "@/src/models/loginModel";
|
import { Account } from "@/src/models/loginModel";
|
||||||
import {
|
import { createAccount, createNonce, getUsernameFromEmail, isCorrectPassword } from "@/src/services/loginService";
|
||||||
createAccount,
|
|
||||||
createNonce,
|
|
||||||
getUsernameFromEmail,
|
|
||||||
isCorrectPassword,
|
|
||||||
isNameTaken
|
|
||||||
} from "@/src/services/loginService";
|
|
||||||
import { IDatabaseAccountJson } from "@/src/types/loginTypes";
|
import { IDatabaseAccountJson } from "@/src/types/loginTypes";
|
||||||
import { HydratedDocument } from "mongoose";
|
import { HydratedDocument } from "mongoose";
|
||||||
import { logError } from "@/src/utils/logger";
|
import { logError } from "@/src/utils/logger";
|
||||||
@ -111,16 +105,14 @@ const wsOnConnect = (ws: ws, req: http.IncomingMessage): void => {
|
|||||||
}
|
}
|
||||||
} else if (data.auth.isRegister) {
|
} else if (data.auth.isRegister) {
|
||||||
const name = await getUsernameFromEmail(data.auth.email);
|
const name = await getUsernameFromEmail(data.auth.email);
|
||||||
if (!(await isNameTaken(name))) {
|
account = await createAccount({
|
||||||
account = await createAccount({
|
email: data.auth.email,
|
||||||
email: data.auth.email,
|
password: data.auth.password,
|
||||||
password: data.auth.password,
|
ClientType: "webui",
|
||||||
ClientType: "webui",
|
LastLogin: new Date(),
|
||||||
LastLogin: new Date(),
|
DisplayName: name,
|
||||||
DisplayName: name,
|
Nonce: createNonce()
|
||||||
Nonce: createNonce()
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (account) {
|
if (account) {
|
||||||
(ws as IWsCustomData).accountId = account.id;
|
(ws as IWsCustomData).accountId = account.id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user