summary refs log tree commit diff
path: root/src/routes/auth
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-06 18:02:10 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-06 18:02:10 +0200
commit70892870161edad2a44ae36bdf9092961ef830bb (patch)
tree4763c7099023784ac7c020ed1dde29223728fd14 /src/routes/auth
parent:bug: fix body parser empty error object (diff)
downloadserver-70892870161edad2a44ae36bdf9092961ef830bb.tar.xz
:art: Convert id bigint to string
Diffstat (limited to 'src/routes/auth')
-rw-r--r--src/routes/auth/login.ts17
-rw-r--r--src/routes/auth/register.ts22
2 files changed, 30 insertions, 9 deletions
diff --git a/src/routes/auth/login.ts b/src/routes/auth/login.ts

index b0936104..3c279319 100644 --- a/src/routes/auth/login.ts +++ b/src/routes/auth/login.ts
@@ -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"} diff --git a/src/routes/auth/register.ts b/src/routes/auth/register.ts
index 9543e814..5fbe610e 100644 --- a/src/routes/auth/register.ts +++ b/src/routes/auth/register.ts
@@ -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) }); }