Skip to content
Closed
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
21 changes: 19 additions & 2 deletions apps/web/src/routes/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Icon } from "@iconify-icon/react";
import { useMutation } from "@tanstack/react-query";
import { createFileRoute } from "@tanstack/react-router";
import { createFileRoute, redirect } from "@tanstack/react-router";
import { useState } from "react";
import { z } from "zod";

import { cn } from "@hypr/utils";

import { Image } from "@/components/image";
import { doAuth, doMagicLinkAuth } from "@/functions/auth";
import { doAuth, doMagicLinkAuth, fetchUser } from "@/functions/auth";

const validateSearch = z.object({
flow: z.enum(["desktop", "web"]).default("web"),
Expand All @@ -17,6 +17,23 @@ const validateSearch = z.object({

export const Route = createFileRoute("/auth")({
validateSearch,
beforeLoad: async ({ search }) => {
const user = await fetchUser();
if (user && search.flow === "web") {
const isUnsafeRedirect =
search.redirect?.startsWith("http://") ||
search.redirect?.startsWith("https://") ||
search.redirect?.startsWith("//");
throw redirect({
to: isUnsafeRedirect
throw redirect({
to: search.redirect && !search.redirect.startsWith('http://') &&
!search.redirect.startsWith('https://') && !search.redirect.startsWith('//')
? search.redirect
: "/app/account",
});
}
},
component: Component,
});

Expand Down
Loading