Skip to content
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(qwik-auth): remove qaction param from defaultCallbackUrl #4936

Merged
merged 2 commits into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/qwik-auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function serverAuthQrl(authOptions: QRL<(ev: RequestEventCommon) => QwikA
'\x1b[33mWARNING: callbackUrl is deprecated - use options.callbackUrl instead\x1b[0m'
);
}
const { callbackUrl = deprecated ?? getCurrentPageForAction(req), ...rest } = options ?? {};
const { callbackUrl = deprecated ?? defaultCallbackURL(req), ...rest } = options ?? {};

const isCredentials = providerId === 'credentials';

Expand Down Expand Up @@ -73,7 +73,7 @@ export function serverAuthQrl(authOptions: QRL<(ev: RequestEventCommon) => QwikA

const useAuthSignout = globalAction$(
async ({ callbackUrl }, req) => {
callbackUrl ??= getCurrentPageForAction(req);
callbackUrl ??= defaultCallbackURL(req);
const auth = await authOptions(req);
const body = new URLSearchParams({ callbackUrl });
await authAction(body, req, `/api/auth/signout`, auth);
Expand Down Expand Up @@ -166,7 +166,10 @@ export const ensureAuthMiddleware = (req: RequestEvent) => {
}
};

const getCurrentPageForAction = (req: RequestEventCommon) => req.url.href.split('q-')[0];
const defaultCallbackURL = (req: RequestEventCommon) => {
req.url.searchParams.delete('qaction');
return req.url.href;
};

async function getSessionData(req: Request, options: AuthConfig): GetSessionResult {
options.secret ??= process.env.AUTH_SECRET;
Expand Down