Skip to content

Commit

Permalink
fix: email login ux (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
thezzisu authored Jan 18, 2024
1 parent fd766f3 commit fc7b5ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .yarn/versions/e5a5f7a7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
releases:
"@aoi-js/frontend": patch
"@aoi-js/server": patch
2 changes: 1 addition & 1 deletion apps/frontend/src/pages/login/mail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@click:append="preLogin"
/>

<VOtpInput v-if="emailSent" v-model="code" />
<VOtpInput v-if="emailSent" v-model.trim="code" />
</VCardText>

<VCardActions v-if="emailSent">
Expand Down
8 changes: 4 additions & 4 deletions apps/server/src/auth/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export class MailAuthProvider extends BaseAuthProvider {
const { code } = payload
const key = this.userKey(userId)
const value = await cache.getx<{ code: string; mail: string }>(key)
await cache.del(key)
if (!value) throw httpErrors.forbidden('Invalid code')
if (value.code !== code) throw httpErrors.forbidden('Invalid code')
await cache.del(key)
await users.updateOne(
{ _id: userId },
{
Expand All @@ -151,9 +151,9 @@ export class MailAuthProvider extends BaseAuthProvider {
const { code } = payload
const key = this.userKey(userId)
const value = await cache.getx<{ code: string; mail: string }>(key)
await cache.del(key)
if (!value) throw httpErrors.forbidden('Invalid code')
if (value.code !== code) throw httpErrors.forbidden('Invalid code')
await cache.del(key)
return true
}

Expand All @@ -176,9 +176,9 @@ export class MailAuthProvider extends BaseAuthProvider {
if (this.allowSignupFromLogin) {
const key = this.mailKey(email)
const value = await cache.getx<{ code: string; mail: string }>(key)
await cache.del(key)
if (!value) throw httpErrors.forbidden('Invalid code')
if (value.code !== code) throw httpErrors.forbidden('Invalid code')
await cache.del(key)
const user = await users.findOne({ 'authSources.mail': email }, { projection: { _id: 1 } })
if (user) return [user._id]
const { insertedId } = await users.insertOne({
Expand All @@ -199,9 +199,9 @@ export class MailAuthProvider extends BaseAuthProvider {
if (!user) throw httpErrors.notFound('User not found')
const key = this.userKey(user._id)
const value = await cache.getx<{ code: string; mail: string }>(key)
await cache.del(key)
if (!value) throw httpErrors.forbidden('Invalid code')
if (value.code !== code) throw httpErrors.forbidden('Invalid code')
await cache.del(key)
return [user._id]
}
}
Expand Down

0 comments on commit fc7b5ac

Please sign in to comment.