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