From 9cffb4d1f3d6c3118629812f1c624321168cc1f9 Mon Sep 17 00:00:00 2001 From: Paradoxe Ngwasi Date: Sat, 27 Jan 2024 15:27:17 +0000 Subject: [PATCH 01/10] implement GET /auth/verify/resend-link api frontend --- apps/web/app/services/client/api/auth.ts | 27 +++++++++++++++++++--- apps/web/lib/features/unverified-email.tsx | 9 ++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/apps/web/app/services/client/api/auth.ts b/apps/web/app/services/client/api/auth.ts index 3c9f7e0b8..6576e4bf7 100644 --- a/apps/web/app/services/client/api/auth.ts +++ b/apps/web/app/services/client/api/auth.ts @@ -1,7 +1,14 @@ import { getRefreshTokenCookie } from '@app/helpers/cookies'; import { ISuccessResponse, IUser } from '@app/interfaces'; import { ILoginResponse, IRegisterDataAPI, ISigninEmailConfirmResponse } from '@app/interfaces/IAuthentication'; -import api, { get } from '../axios'; +import api, { get, post } from '../axios'; +import { + APP_LOGO_URL, + APP_NAME, + APP_SIGNATURE, + VERIFY_EMAIL_CALLBACK_PATH, + VERIFY_EMAIL_CALLBACK_URL +} from '@app/constants'; export const signInWithEmailAndCodeAPI = (email: string, code: string) => { return api.post(`/auth/login`, { @@ -66,6 +73,20 @@ export const verifyUserEmailByTokenAPI = (email: string, token: string) => { return api.post(`/auth/verify/token`, { email, token }); }; -export const resentVerifyUserLinkAPI = () => { - return api.post(`/auth/verify/resend-link`); +export const resentVerifyUserLinkAPI = (user: IUser) => { + const appEmailConfirmationUrl = `${location.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; + const registerDefaultValue = { + appName: APP_NAME, + appSignature: APP_SIGNATURE, + appLogo: APP_LOGO_URL + }; + + const body = { + email: user.email, + tenantId: user.tenantId, + ...registerDefaultValue, + appEmailConfirmationUrl: VERIFY_EMAIL_CALLBACK_URL || appEmailConfirmationUrl + }; + + return post(`/auth/verify/resend-link`, body); }; diff --git a/apps/web/lib/features/unverified-email.tsx b/apps/web/lib/features/unverified-email.tsx index 132454cd9..3abe9f9cc 100644 --- a/apps/web/lib/features/unverified-email.tsx +++ b/apps/web/lib/features/unverified-email.tsx @@ -2,6 +2,7 @@ import { getAccessTokenCookie } from '@app/helpers'; import { useAuthenticateUser, useModal, useQuery } from '@app/hooks'; +import { IUser } from '@app/interfaces'; import { resentVerifyUserLinkAPI, verifyUserEmailByCodeAPI } from '@app/services/client/api'; import { clsxm } from '@app/utils'; import { AuthCodeInputField, Button, Card, Modal, SpinnerLoader, Text } from 'lib/components'; @@ -57,7 +58,7 @@ export function UnverifiedEmail() { @@ -69,14 +70,14 @@ export function UnverifiedEmail() { */} - + ) : ( <> ); } -export function ConfirmUserModal({ open, closeModal }: { open: boolean; closeModal: () => void }) { +export function ConfirmUserModal({ open, user, closeModal }: { open: boolean; user?: IUser; closeModal: () => void }) { const { loading, queryCall } = useQuery(verifyUserEmailByCodeAPI); const { loading: resendLinkLoading, queryCall: resendLinkQueryCall } = useQuery(resentVerifyUserLinkAPI); @@ -128,7 +129,7 @@ export function ConfirmUserModal({ open, closeModal }: { open: boolean; closeMod