🎨 Convert id bigint to string
This commit is contained in:
@@ -25,12 +25,20 @@ router.post(
|
||||
const query: any[] = [{ phone: login }];
|
||||
if (email) query.push({ email });
|
||||
|
||||
// * MongoDB Specific query for user with same email or phone number
|
||||
const user = await UserModel.findOne(
|
||||
{
|
||||
$or: query,
|
||||
},
|
||||
`user_data.hash id user_settings.locale user_settings.theme`
|
||||
{
|
||||
id: true,
|
||||
user_settings: {
|
||||
locale: true,
|
||||
theme: true,
|
||||
},
|
||||
user_data: {
|
||||
hash: true,
|
||||
},
|
||||
}
|
||||
).exec();
|
||||
|
||||
if (!user) {
|
||||
@@ -57,13 +65,13 @@ router.post(
|
||||
}
|
||||
);
|
||||
|
||||
export async function generateToken(id: bigint) {
|
||||
export async function generateToken(id: string) {
|
||||
const iat = Math.floor(Date.now() / 1000);
|
||||
const algorithm = "HS256";
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
jwt.sign(
|
||||
{ id: `${id}`, iat },
|
||||
{ id: id, iat },
|
||||
Config.get().security.jwtSecret,
|
||||
{
|
||||
algorithm,
|
||||
@@ -80,7 +88,6 @@ export async function generateToken(id: bigint) {
|
||||
* POST /auth/login
|
||||
* @argument { login: "email@gmail.com", password: "cleartextpassword", undelete: false, captcha_key: null, login_source: null, gift_code_sku_id: null, }
|
||||
|
||||
|
||||
* MFA required:
|
||||
* @returns {"token": null, "mfa": true, "sms": true, "ticket": "SOME TICKET JWT TOKEN"}
|
||||
|
||||
|
||||
@@ -166,10 +166,9 @@ router.post(
|
||||
}
|
||||
|
||||
// TODO: save date_of_birth
|
||||
// appearently discord doesn't save the date of birth and just calculate if nsfw is allowed
|
||||
// if nsfw_allowed is null/undefined it'll require date_of_birth to set it to true/false
|
||||
|
||||
// constructing final user object
|
||||
// TODO fix:
|
||||
// @ts-ignore
|
||||
const user: User = {
|
||||
id: Snowflake.generate(),
|
||||
created_at: new Date(),
|
||||
@@ -178,10 +177,25 @@ router.post(
|
||||
avatar: null,
|
||||
bot: false,
|
||||
system: false,
|
||||
desktop: false,
|
||||
mobile: false,
|
||||
premium: false,
|
||||
premium_type: 0,
|
||||
phone: undefined,
|
||||
mfa_enabled: false,
|
||||
verified: false,
|
||||
presence: {
|
||||
activities: [],
|
||||
client_status: {
|
||||
desktop: undefined,
|
||||
mobile: undefined,
|
||||
web: undefined,
|
||||
},
|
||||
status: "offline",
|
||||
},
|
||||
email: adjusted_email,
|
||||
nsfw_allowed: true, // TODO: depending on age
|
||||
public_flags: 0n,
|
||||
flags: 0n, // TODO: generate default flags
|
||||
guilds: [],
|
||||
user_data: {
|
||||
@@ -233,7 +247,7 @@ router.post(
|
||||
};
|
||||
|
||||
// insert user into database
|
||||
await new UserModel(user).save({});
|
||||
await new UserModel(user).save();
|
||||
|
||||
return res.json({ token: await generateToken(user.id) });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user