fix(login): redirect back to profile is ignored so it will not cause confusion
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Link, useRouter, useSearch } from "@tanstack/react-router";
|
||||
import { Link, useNavigate } from "@tanstack/react-router";
|
||||
import axios from "axios";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
@@ -11,13 +11,13 @@ import { LstCard } from "../../../../components/ui/lstCard";
|
||||
import { getSession, useAuth, useUserRoles } from "../../../../lib/authClient";
|
||||
import { useAppForm } from "../../../../lib/formStuff";
|
||||
|
||||
export default function LoginForm() {
|
||||
const router = useRouter();
|
||||
const search = useSearch({ from: "/_app/(auth)/login" });
|
||||
export default function LoginForm({ redirectPath }: { redirectPath: string }) {
|
||||
//const search = useSearch({ from: "/_app/(auth)/login" });
|
||||
const username = localStorage.getItem("username") || "";
|
||||
const rememberMe = localStorage.getItem("rememberMe") === "true";
|
||||
const { setSession } = useAuth();
|
||||
const { fetchRoles } = useUserRoles();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const form = useAppForm({
|
||||
defaultValues: {
|
||||
@@ -48,8 +48,12 @@ export default function LoginForm() {
|
||||
toast.success(
|
||||
`Welcome back ${session?.user.name ? session?.user.name : session?.user.username} `,
|
||||
);
|
||||
router.invalidate();
|
||||
router.history.push(search.redirect ? search.redirect : "/");
|
||||
//router.invalidate();
|
||||
if (redirectPath.includes("profile")) {
|
||||
navigate({ to: "/" });
|
||||
} else {
|
||||
navigate({ to: redirectPath });
|
||||
}
|
||||
} catch (error) {
|
||||
// @ts-ignore
|
||||
if (!error.response.data.success) {
|
||||
|
||||
Reference in New Issue
Block a user