mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-06 00:04:39 +00:00
feat: add login redirect to the page which initiated auth
This commit is contained in:
parent
d28011b4fb
commit
3378d5b99e
7 changed files with 12 additions and 14 deletions
6
TODO.md
6
TODO.md
|
@ -37,11 +37,7 @@
|
|||
|
||||
### Авторизация
|
||||
|
||||
- [ ] Перенаправление на страницу с которой был запрос на авторизацию
|
||||
|
||||
или
|
||||
|
||||
- [ ] Использование Modal вместо отдельной страницы
|
||||
- [X] Перенаправление на страницу с которой был запрос на авторизацию после успешной авторизации
|
||||
|
||||
### Рекомендации (Обзор)
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ export const Navbar = () => {
|
|||
>
|
||||
<Dropdown.Item className="text-sm md:text-base">
|
||||
<Link
|
||||
href="/login"
|
||||
href={pathname != "/login" ? `/login?redirect=${pathname}` : "#"}
|
||||
className="flex items-center gap-1"
|
||||
>
|
||||
<span
|
||||
|
|
|
@ -34,7 +34,7 @@ export function BookmarksPage() {
|
|||
|
||||
useEffect(() => {
|
||||
if (authState === "finished" && !token) {
|
||||
router.push("/login");
|
||||
router.push("/login?redirect=/bookmarks");
|
||||
}
|
||||
}, [authState, token]);
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ export function BookmarksCategoryPage(props: any) {
|
|||
|
||||
useEffect(() => {
|
||||
if (authState === "finished" && !token) {
|
||||
router.push("/login");
|
||||
router.push(`/login?redirect=/bookmarks/${props.slug}`);
|
||||
}
|
||||
}, [authState, token]);
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ export function FavoritesPage() {
|
|||
|
||||
useEffect(() => {
|
||||
if (authState === "finished" && !token) {
|
||||
router.push("/login");
|
||||
router.push("/login?redirect=/favorites");
|
||||
}
|
||||
}, [authState, token]);
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ export function HistoryPage() {
|
|||
|
||||
useEffect(() => {
|
||||
if (authState === "finished" && !token) {
|
||||
router.push("/login");
|
||||
router.push("/login?redirect=/history");
|
||||
}
|
||||
}, [authState, token]);
|
||||
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { useUserStore } from "#/store/auth";
|
||||
import { setJWT } from "#/api/utils";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
|
||||
export function LoginPage() {
|
||||
const [login, setLogin] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [remember, setRemember]: any = useState(false);
|
||||
const [remember, setRemember] = useState(true);
|
||||
const userStore = useUserStore();
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const redirect = searchParams.get("redirect") || null;
|
||||
|
||||
function submit(e) {
|
||||
e.preventDefault();
|
||||
|
@ -45,7 +47,7 @@ export function LoginPage() {
|
|||
|
||||
useEffect(() => {
|
||||
if (userStore.user) {
|
||||
router.push("/");
|
||||
router.push(`${redirect || "/"}`);
|
||||
}
|
||||
}, [userStore.user]);
|
||||
|
||||
|
@ -108,7 +110,7 @@ export function LoginPage() {
|
|||
type="checkbox"
|
||||
className="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-primary-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-primary-600 dark:ring-offset-gray-800"
|
||||
required={true}
|
||||
value={remember}
|
||||
checked={remember}
|
||||
onChange={(e) => setRemember(e.target.checked)}
|
||||
/>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue