Will beforeLoad prevent the OAuth authorization page from redirecting?
I have three key configurations, and when I click the login button, the page fails to redirect to the OAuth authorization page. The log shows that all paths' beforeLoad are executed again, which is described as normal in the documentation, but I don't understand why the authorization cannot redirect.
// root.tsx
const getUser = createServerFn({ method: "GET" }).handler(async () => {
const { headers } = getWebRequest()!;
const session = await auth.api.getSession({ headers });
return session?.user || null;
});
export const Route = createRootRoute({
beforeLoad: async () => {
console.log("root beforeLoad");
const user = await getUser();
return { user };
},
...
// index.tsx
export const Route = createFileRoute("/")({
component: () => {},
beforeLoad: ({ context, location }) => {
console.log("index beforeLoad");
if (!context.user) {
throw redirect({
to: "/login",
search: {
redirect: location.href,
},
});
} else {
throw redirect({ to: "/project" });
}
},
});
// login.tsx
export const Route = createFileRoute("/login")({
component: LoginPage,
beforeLoad: async ({ context }) => {
console.log("login beforeLoad");
if (context.user) {
throw redirect({
to: REDIRECT_URL,
});
}
},
});
// root.tsx
const getUser = createServerFn({ method: "GET" }).handler(async () => {
const { headers } = getWebRequest()!;
const session = await auth.api.getSession({ headers });
return session?.user || null;
});
export const Route = createRootRoute({
beforeLoad: async () => {
console.log("root beforeLoad");
const user = await getUser();
return { user };
},
...
// index.tsx
export const Route = createFileRoute("/")({
component: () => {},
beforeLoad: ({ context, location }) => {
console.log("index beforeLoad");
if (!context.user) {
throw redirect({
to: "/login",
search: {
redirect: location.href,
},
});
} else {
throw redirect({ to: "/project" });
}
},
});
// login.tsx
export const Route = createFileRoute("/login")({
component: LoginPage,
beforeLoad: async ({ context }) => {
console.log("login beforeLoad");
if (context.user) {
throw redirect({
to: REDIRECT_URL,
});
}
},
});
