Skip to content

Commit

Permalink
Rename signin code to cvxAuthCode
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasballinger committed Dec 20, 2024
1 parent e6cbdc6 commit 3c35da8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/nextjs/server/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function handleAuthenticationInRequest(
const refreshTokens = await getRefreshedTokens(verbose);

// Handle code exchange for OAuth and magic links via server-side redirect
const code = requestUrl.searchParams.get("code");
const code = requestUrl.searchParams.get("cvxAuthCode");
if (
code &&
request.method === "GET" &&
Expand All @@ -35,7 +35,7 @@ export async function handleAuthenticationInRequest(
logVerbose(`Handling code exchange for OAuth or magic link`, verbose);
const verifier = (await getRequestCookies()).verifier ?? undefined;
const redirectUrl = new URL(requestUrl);
redirectUrl.searchParams.delete("code");
redirectUrl.searchParams.delete("cvxAuthCode");
try {
const result = await fetchAction(
"auth:signIn" as unknown as SignInAction,
Expand Down
12 changes: 7 additions & 5 deletions src/react/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ export function AuthProvider({

const verifyCodeAndSetToken = useCallback(
async (
args: { code: string; verifier?: string } | { refreshToken: string },
args:
| { cvxAuthCode: string; verifier?: string }
| { refreshToken: string },
) => {
const { tokens } = await client.unauthenticatedCall(
"auth:signIn" as unknown as SignInAction,
"code" in args
? { params: { code: args.code }, verifier: args.verifier }
"cvxAuthCode" in args
? { params: { code: args.cvxAuthCode }, verifier: args.verifier }
: args,
);
logVerbose(`retrieved tokens, is null: ${tokens === null}`);
Expand Down Expand Up @@ -322,15 +324,15 @@ export function AuthProvider({
}
const code =
typeof window?.location !== "undefined"
? new URLSearchParams(window.location.search).get("code")
? new URLSearchParams(window.location.search).get("cvxAuthCode")
: null;
// code from URL is only consumed initially,
// ref avoids racing in Strict mode
if (signingInWithCodeFromURL.current || code) {
if (code && !signingInWithCodeFromURL.current) {
signingInWithCodeFromURL.current = true;
const url = new URL(window.location.href);
url.searchParams.delete("code");
url.searchParams.delete("cvxAuthCode");
void (async () => {
await replaceURL(url.pathname + url.search + url.hash);
await signIn(undefined, { code });
Expand Down
2 changes: 1 addition & 1 deletion src/server/implementation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export function convexAuth(config_: ConvexAuthConfig) {
headers: {
Location: setURLSearchParam(
destinationUrl,
"code",
"cvxAuthCode",
verificationCode,
),
"Cache-Control": "must-revalidate",
Expand Down
2 changes: 1 addition & 1 deletion test-nextjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c35da8

Please sign in to comment.