-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fixed magic link issues in dev environment #32
Changes from 22 commits
613a39e
108bbbd
108deda
3617447
4a95aa8
c1436b2
a745140
7749eb7
a79bca9
8277c07
ad985f4
87b2dcd
371bf74
605667b
13f2db1
6df4b54
1566bc2
fdb04a1
810e74f
1be53a4
303b8b8
71f013b
db476ea
65ff8bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default defineNuxtRouteMiddleware((to) => { | ||
const localePath = useLocalePath() | ||
|
||
// Check if path contains affiliationInvitation and extract token | ||
if (to.path.includes('affiliationInvitation/acceptToken/')) { | ||
const token = to.path.split('acceptToken/')[1] | ||
if (token) { | ||
sessionStorage.setItem('affiliationToken', token) | ||
} | ||
window.location.href = localePath('/') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, if the path contains a token then you save it to session storage and then reload everything? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, exactly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why so complicated? Why can't the token be handled directly? Why is a reload needed? Could you just push a new route? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because any route that is not that the main route will give a page 404 error: Whenever that link is pressed, we will get an error if we don't handle it using a middleware or something else. It's not possible to handle it from the When I tried handling that via an actual route, I was getting that error as well since the email returned has a double slash There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be an issue now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I want to understand the new design. |
||
} | ||
}) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,78 @@ | ||
<script setup lang="ts"> | ||
const { t } = useI18n() | ||
const affStore = useAffiliationsStore() | ||
const brdModal = useBrdModals() | ||
const toast = useToast() | ||
|
||
definePageMeta({ | ||
order: 0 | ||
}) | ||
|
||
// Token parsing | ||
const parseToken = (encodedToken: string): AffiliationToken => { | ||
try { | ||
const tokenObject = encodedToken.split('.')[0] | ||
const decoded = atob(tokenObject as string) | ||
return JSON.parse(decoded) | ||
} catch (error) { | ||
console.error('Failed to parse token:', error) | ||
throw new Error('Invalid token format') | ||
} | ||
} | ||
|
||
onMounted(async () => { | ||
// Check for affiliation token from session storage | ||
if (sessionStorage.getItem('affiliationToken')) { | ||
const affiliationToken = sessionStorage.getItem('affiliationToken') as string | ||
// Remove the token from session storage after it's used | ||
sessionStorage.removeItem('affiliationToken') | ||
try { | ||
const parsedToken = parseToken(affiliationToken) | ||
// Parse the URL and try to add the affiliation | ||
parseUrlAndAddAffiliation(parsedToken, affiliationToken) | ||
// Load affiliations to update the table | ||
await affStore.loadAffiliations() | ||
} catch (e) { | ||
console.error('Error accepting affiliation invitation:', e) | ||
} | ||
} | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love this design of "check URL parameters + set session storage + reload + check session storage + handle token". It feels complicated and I keep thinking there are edge cases. Can you check this design with someone else, like Travis? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, will check with Travis now and see what he thinks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be an issue now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
So what's the new design? Does it still update the URL, reload everything, etc? |
||
|
||
// Function to parse the URL and extract the parameters, used for magic link email | ||
const parseUrlAndAddAffiliation = async (token: any, base64Token: string) => { | ||
const { businessIdentifier: identifier, id: invitationId } = token | ||
|
||
try { | ||
// 1. Accept invitation | ||
const response = await affiliationInvitationService.acceptInvitation(invitationId, base64Token) | ||
|
||
// 2. Adding magic link success | ||
if (response.status === AffiliationInvitationStatus.Accepted) { | ||
toast.add({ title: t('modal.manageBusiness.success.toast', { identifier }) }) // add success toast | ||
} | ||
} catch (error: any) { | ||
console.error(error) | ||
// 3. Unauthorized | ||
if (error.response?.status === 401) { | ||
JazzarKarim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
brdModal.openMagicLinkModal(t('error.magicLinkUnauthorized.title'), t('error.magicLinkUnauthorized.description')) | ||
return | ||
} | ||
// 4. Expired | ||
if (error.response?.status === 400 && | ||
error.response?._data.code === MagicLinkInvitationStatus.EXPIRED_AFFILIATION_INVITATION) { | ||
brdModal.openMagicLinkModal(t('error.magicLinkExpired.title'), t('error.magicLinkExpired.description', { identifier })) | ||
return | ||
} | ||
// 5. Already Added | ||
if (error.response?.status === 400 && | ||
error.response?._data.code === MagicLinkInvitationStatus.ACTIONED_AFFILIATION_INVITATION) { | ||
brdModal.openMagicLinkModal(t('error.magicLinkAlreadyAdded.title'), t('error.magicLinkAlreadyAdded.description', { identifier })) | ||
return | ||
} | ||
// 6. Generic Error | ||
brdModal.openBusinessAddError() | ||
} | ||
} | ||
</script> | ||
<template> | ||
<NuxtLayout name="dashboard"> | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this old function do anything extra (like set URL parameters)?
Does it matter that the old code sometimes returns something and the new code doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I changed this Sev to use the new
window.location.href
only if the URL has a token.What the old one is doing basically is the same as the new one except for the fact that
window.location.href = localePath('/')
causes a full page reload which is needed in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed?