-
Hi, I have auth middleware using Hono: // Authorization using callback from IDP
if (c.req.path.includes(callbackRoute) && c.req.method === "GET") {
const params = getLoginParamsFromSession(session);
if (!params) {
return reactRouterRedirect("/");
}
const { route, ...verifyParams } = params;
const url = new URL(c.req.raw.url);
const callbackUri = `${getHost(c)}${url.pathname}${url.search}`;
try {
const tokens = await client.validateAuthorizationCallback(
callbackUri,
verifyParams
);
removeLoginParamsFromSession(session);
setTokensToSession(tokens, session);
c.set("access_token", tokens.accessToken);
c.set("user", parseUserDataFromAccessToken(tokens.accessToken));
} catch (e) {
console.error("⛔️ Failed validateAuthorizationCallback", e);
}
return reactRouterRedirect(route);
} If I redirect using c.redirect it works, but if I redirect using new function reactRouterRedirect, it throw the following message in the browser:
AuthMiddleware runs before react router. Can you please help me what i am doing wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
rphlmr
Jan 6, 2025
Replies: 1 comment 2 replies
-
Hi 👋 |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
jezikk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi 👋
If c.redirect works, then keep using it. Actually we should use it in priority.
reactRouterRedirect is here just in case you encounter a “turbo stream” error.