mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
added redirect after login (#325)
The old behaviour was: You open a page without being authorized, you are getting redirected to /login that redirects you after a successful authentication to /dashboard. This is really annoying if you want to open listenings directly from your notification adapter for example. This commit introduces a method to redirect you back to the original page you opened after the authentication process by adding the navigation of the opened page as state to the navigation to /login. The login component than unpacks the state that contains the old navigation and redirects the user back to path from the original navigation. The path /dashboard is used as a fallback if no navigation in the state is present.
This commit is contained in:
committed by
GitHub
parent
c132e64437
commit
6c7d655277
@@ -8,7 +8,7 @@ import React, { useEffect } from 'react';
|
||||
import cityBackground from '../../assets/city_background.jpg';
|
||||
import Logo from '../../components/logo/Logo';
|
||||
import { xhrPost } from '../../services/xhr';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { useActions, useSelector } from '../../services/state/store';
|
||||
import { Input, Button, Banner } from '@douyinfe/semi-ui-19';
|
||||
|
||||
@@ -24,6 +24,7 @@ export default function Login() {
|
||||
const [error, setError] = React.useState(null);
|
||||
const demoMode = useSelector((state) => state.demoMode.demoMode || false);
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
async function init() {
|
||||
@@ -52,7 +53,7 @@ export default function Login() {
|
||||
}
|
||||
|
||||
await actions.user.getCurrentUser();
|
||||
navigate('/dashboard');
|
||||
navigate(location.state?.from?.pathname || '/dashboard');
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user