diff --git a/web/satellite/src/api/auth.ts b/web/satellite/src/api/auth.ts index 38f68433d..4f1db0901 100644 --- a/web/satellite/src/api/auth.ts +++ b/web/satellite/src/api/auth.ts @@ -29,13 +29,14 @@ export class AuthHttpApi implements UsersApi { * Used to resend an registration confirmation email. * * @param email - email of newly created user + * @returns requestID to be used for code activation. * @throws Error */ - public async resendEmail(email: string): Promise { + public async resendEmail(email: string): Promise { const path = `${this.ROOT_PATH}/resend-email/${email}`; const response = await this.http.post(path, email); if (response.ok) { - return; + return response.headers.get('x-request-id') ?? ''; } const result = await response.json(); @@ -98,6 +99,41 @@ export class AuthHttpApi implements UsersApi { } } + /** + * Used to verify signup code. + * @param email + * @param code - the code to verify + * @param signupId - the request ID of the signup request or resend email request + */ + public async verifySignupCode(email: string, code: string, signupId: string): Promise { + const path = `${this.ROOT_PATH}/code-activation`; + const body = { + email, + code, + signupId, + }; + + const response = await this.http.patch(path, JSON.stringify(body)); + const result = await response.json(); + if (response.ok) { + return new TokenInfo(result.token, new Date(result.expiresAt)); + } + + const errMsg = result.error || 'Failed to activate account'; + switch (response.status) { + case 400: + throw new ErrorBadRequest(errMsg); + case 429: + throw new ErrorTooManyRequests(errMsg); + default: + throw new APIError({ + status: response.status, + message: errMsg, + requestID: response.headers.get('x-request-id'), + }); + } + } + /** * Used to logout user and delete auth cookie. * @@ -351,10 +387,10 @@ export class AuthHttpApi implements UsersApi { * @param user - stores user information * @param secret - registration token used in Vanguard release * @param captchaResponse - captcha response - * @returns id of created user + * @returns requestID to be used for code activation. * @throws Error */ - public async register(user: Partial, secret: string, captchaResponse: string): Promise { + public async register(user: Partial, secret: string, captchaResponse: string): Promise { const path = `${this.ROOT_PATH}/register`; const body = { secret: secret, @@ -374,21 +410,22 @@ export class AuthHttpApi implements UsersApi { }; const response = await this.http.post(path, JSON.stringify(body)); - if (!response.ok) { - const result = await response.json(); - const errMsg = result.error || 'Cannot register user'; - switch (response.status) { - case 400: - throw new ErrorBadRequest(errMsg); - case 429: - throw new ErrorTooManyRequests(errMsg); - default: - throw new APIError({ - status: response.status, - message: errMsg, - requestID: response.headers.get('x-request-id'), - }); - } + if (response.ok) { + return response.headers.get('x-request-id') ?? ''; + } + const result = await response.json(); + const errMsg = result.error || 'Cannot register user'; + switch (response.status) { + case 400: + throw new ErrorBadRequest(errMsg); + case 429: + throw new ErrorTooManyRequests(errMsg); + default: + throw new APIError({ + status: response.status, + message: errMsg, + requestID: response.headers.get('x-request-id'), + }); } } diff --git a/web/satellite/src/components/account/mfa/ConfirmMFAInput.vue b/web/satellite/src/components/account/mfa/ConfirmMFAInput.vue index 925933cf7..b1f4b611e 100644 --- a/web/satellite/src/components/account/mfa/ConfirmMFAInput.vue +++ b/web/satellite/src/components/account/mfa/ConfirmMFAInput.vue @@ -4,7 +4,7 @@