Repository navigation
feat(core): add cancelEmailChange API
#296
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
Merged
halvaradop
merged 6 commits into
feat/add-change-email-api
from
feat/add-cancel-email-change-api
Nov 6, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
516db0d
feat(core): support email change cancellation
halvaradop aa933c1
test(core): update changeEmail tests for the new API
halvaradop 4cc89f0
feat(core): add `cancelEmailChange` API
halvaradop bed11b5
feat(prisma): add getTokensByUserId support function
halvaradop 7e49266
docs(core): update CHANGELOG.md file
halvaradop 2f47502
chore(core): apply suggested changes
halvaradop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { createEndpoint, createEndpointConfig } from "@aura-stack/router" | ||
| import { cancelEmailChange } from "@/api/cancel-email-change.ts" | ||
| import { CancelEmailChangeResponseSchema, CancelEmailChangeSearchParamsSchema } from "@/shared/schemas/actions.ts" | ||
|
|
||
| const cancelEmailChangeActionConfig = () => { | ||
| return createEndpointConfig({ | ||
| schemas: { | ||
| searchParams: CancelEmailChangeSearchParamsSchema, | ||
| response: CancelEmailChangeResponseSchema, | ||
| }, | ||
| hooks: { | ||
| onError: (ctx) => { | ||
| return ctx.json( | ||
| { | ||
| type: "VALIDATION", | ||
| code: "INVALID_VERIFICATION_TOKEN", | ||
| message: "Invalid or expired verification token", | ||
| }, | ||
| { status: 422 } | ||
| ) | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| export const cancelEmailChangeAction = () => { | ||
| return createEndpoint( | ||
| "GET", | ||
| "/email/change/cancel", | ||
| async (ctx) => { | ||
| const { toResponse } = await cancelEmailChange({ | ||
| ctx: ctx.context, | ||
| payload: ctx.searchParams.token ? { token: ctx.searchParams.token } : undefined, | ||
| request: ctx.request, | ||
| headers: ctx.request.headers, | ||
| redirect: ctx.searchParams.redirect, | ||
| redirectTo: ctx.searchParams.redirectTo, | ||
| skipCSRFCheck: false, | ||
| }) | ||
| return toResponse() | ||
| }, | ||
| cancelEmailChangeActionConfig() | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { HeadersBuilder } from "@aura-stack/router" | ||
| import { secureApiHeaders, toStandardizedHeaders } from "@/shared/http/headers.ts" | ||
| import { createValidation, errorToLogMessage, handleApiError, resolveApiRedirect } from "@/shared/utils/api.ts" | ||
| import type { FunctionAPIContext } from "@/@types/internal.ts" | ||
| import type { CancelEmailChangeAPIOptions, CancelEmailChangeAPIReturn } from "@/@types/api.ts" | ||
|
|
||
| export const cancelEmailChange = async ({ | ||
| ctx, | ||
| payload, | ||
| headers: headersInit, | ||
| request: requestInit, | ||
| redirectTo, | ||
| redirect: redirectInit = true, | ||
| skipCSRFCheck = false, | ||
| doubleSubmitToken = undefined, | ||
| }: FunctionAPIContext<CancelEmailChangeAPIOptions>): Promise<CancelEmailChangeAPIReturn> => { | ||
| const { logger, sessionStrategy } = ctx | ||
| try { | ||
| logger?.log("CANCEL_EMAIL_CHANGE_INITIATED", { | ||
| structuredData: { | ||
| skipCSRFCheck: skipCSRFCheck, | ||
| doubleSubmitToken: doubleSubmitToken ? "provided" : "not_provided", | ||
| hasToken: Boolean(payload?.token), | ||
| }, | ||
| }) | ||
|
|
||
| const validation = createValidation(ctx, toStandardizedHeaders(headersInit ?? requestInit?.headers ?? {})) | ||
| .buildRequest(requestInit, "/email/change/cancel") | ||
| .verifyRateLimit("cancelEmailChange") | ||
|
|
||
| if (payload?.token) { | ||
| const { request, rateLimit } = await validation.execute() | ||
| requestInit = requestInit ?? request | ||
|
|
||
| if (rateLimit) { | ||
| return rateLimit | ||
| } | ||
|
halvaradop marked this conversation as resolved.
Resolved
|
||
|
|
||
| await sessionStrategy.cancelEmailChange({ | ||
| token: payload?.token, | ||
| userId: undefined, | ||
| }) | ||
| } else { | ||
| const { request, rateLimit, userId } = await validation | ||
| .verifyCSRFToken(skipCSRFCheck, doubleSubmitToken) | ||
| .verifySession() | ||
| .execute() | ||
| requestInit = requestInit ?? request | ||
|
|
||
| if (rateLimit) { | ||
| return rateLimit | ||
| } | ||
|
|
||
| await sessionStrategy.cancelEmailChange({ | ||
| token: undefined, | ||
| userId: userId!, | ||
| }) | ||
| } | ||
|
|
||
| const headers = new HeadersBuilder(secureApiHeaders) | ||
| const { redirect, redirectURL } = await resolveApiRedirect(ctx, requestInit, redirectInit, redirectTo, headers) | ||
| const headersList = headers.toHeaders() | ||
|
|
||
| return { | ||
| success: true, | ||
| redirect, | ||
| redirectURL: redirectInit ? null : redirectURL, | ||
| headers: headersList, | ||
| toResponse: () => { | ||
| return Response.json( | ||
| { | ||
| success: true, | ||
| redirect, | ||
| redirectURL: redirect ? null : redirectURL, | ||
| }, | ||
| { headers: headersList, status: redirect ? 302 : 200 } | ||
| ) | ||
| }, | ||
| } as CancelEmailChangeAPIReturn | ||
| } catch (error) { | ||
| errorToLogMessage(error, "CANCEL_EMAIL_CHANGE_ERROR", logger) | ||
| const { errors, statusCode } = handleApiError( | ||
| error, | ||
| "CANCEL_EMAIL_CHANGE_ERROR", | ||
| "An error occurred while canceling the email change." | ||
| ) | ||
| return { | ||
| success: false, | ||
| error: errors, | ||
| redirect: false, | ||
| redirectURL: null, | ||
| headers: new Headers(secureApiHeaders), | ||
| toResponse: () => { | ||
| return Response.json( | ||
| { | ||
| success: false, | ||
| redirect: false, | ||
| redirectURL: null, | ||
| }, | ||
| { headers: secureApiHeaders, status: statusCode } | ||
| ) | ||
| }, | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.