Skip to content

Commit

Permalink
Fixed some email verification corner case problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed May 12, 2024
1 parent 42951a1 commit 14a30ee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
27 changes: 16 additions & 11 deletions pages/user/verify-email.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@

<script setup>
const config = useRuntimeConfig();
const message = ref('Please wait while we verify your email address.');
const currentUser = useCurrentUser();
const query = useRoute().query;
await currentUser.verifyEmail(query.verify?.toString());
if (currentUser.props?.verifiedEmail) {
message.value = 'Email address successfully verified.';
if (currentUser.meta?.redirectAfter)
await navigateTo(currentUser.meta.redirectAfter);
else
await navigateTo('/');
if (await currentUser.isAuthenticated()) {
const message = ref('Please wait while we verify your email address.');
const query = useRoute().query;
await currentUser.verifyEmail(query.verify?.toString());
if (currentUser.props?.verifiedEmail) {
message.value = 'Email address successfully verified.';
if (currentUser.meta?.redirectAfter && !currentUser.meta?.redirectAfter?.match(/verify-email/))
await navigateTo(currentUser.meta.redirectAfter);
else
await navigateTo('/');
}
else {
message.value = 'Verification failed.';
}
}
else {
message.value = 'Verification failed.';
await navigateTo('/user/login')
}
</script>
16 changes: 15 additions & 1 deletion server/api/v1/user/[id]/verify-email.post.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@ import { useKind } from '#ving/record/utils.mjs';
import { obtainSession, describeParams } from '#ving/utils/rest.mjs';
import { useCache } from '#ving/cache.mjs';
import { defineEventHandler, getRouterParams, getQuery } from 'h3';

import { log } from '#ving/log.mjs';

export default defineEventHandler(async (event) => {
log('test').info('a');
const users = await useKind('User');
log('test').info('b');
const { id } = getRouterParams(event);
log('test').info('c');
const user = await users.findOrDie(id);
log('test').info('d');
await user.canEdit(obtainSession(event));
log('test').info('e');
const query = getQuery(event);
log('test').info('f');
const result = await useCache().get('verifyEmail-' + query.verify);
log('test').info('g');
if (result && result.userId == id) {
log('test').info('h');
user.set('verifiedEmail', true);
log('test').info('i');
await user.update();
log('test').info('j');
const out = await user.describe(describeParams(event));
log('test').info('k');
if (!out.meta)
out.meta = {};
log('test').info('l');
out.meta.redirectAfter = result.redirectAfter;
log('test').info('m');
await useCache().delete('verifyEmail-' + query.verify);
log('test').info(out);
return out;
}
return await user.describe(describeParams(event));
Expand Down
1 change: 1 addition & 0 deletions ving/docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ outline: deep
## 2024-05-11
* VingRecord id's are now integers for better database performance. They are translated to encrypted strings on the API for better security.
* NOTE: You will likely want to recreate your database from scratch as all primary and foreign keys are changing from strings to integers, and doing a migration for that is going to be challenging.
* Fixed some email verification corner case problems.

## 2024-05-06
* Updated useVingRecord() to allow for extended actions.
Expand Down

0 comments on commit 14a30ee

Please sign in to comment.