feat: login redirect
This commit is contained in:
parent
dd769e4d04
commit
44633db5ff
@ -1,3 +1,4 @@
|
|||||||
|
import { Card } from 'antd';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useLocation, useHistory } from 'react-router-dom';
|
import { useLocation, useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
@ -5,7 +6,7 @@ export function AuthLayout({ children, route }: any) {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
return (
|
return (
|
||||||
<div style={{ maxWidth: 320, margin: '0 auto' }}>
|
<div style={{ maxWidth: 320, margin: '0 auto', paddingTop: '20vh' }}>
|
||||||
<h1>NocoBase</h1>
|
<h1>NocoBase</h1>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,7 +4,7 @@ import { Helmet } from 'react-helmet';
|
|||||||
import { useRequest } from 'ahooks';
|
import { useRequest } from 'ahooks';
|
||||||
import { request, SchemaRenderer } from '../../schemas';
|
import { request, SchemaRenderer } from '../../schemas';
|
||||||
import { useForm } from '@formily/react';
|
import { useForm } from '@formily/react';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
function Div(props) {
|
function Div(props) {
|
||||||
return <div {...props}></div>;
|
return <div {...props}></div>;
|
||||||
@ -13,6 +13,9 @@ function Div(props) {
|
|||||||
export function useLogin() {
|
export function useLogin() {
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const location = useLocation<any>();
|
||||||
|
const query = new URLSearchParams(location.search);
|
||||||
|
const redirect = query.get('redirect');
|
||||||
return {
|
return {
|
||||||
async run() {
|
async run() {
|
||||||
await form.submit();
|
await form.submit();
|
||||||
@ -20,9 +23,8 @@ export function useLogin() {
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
data: form.values,
|
data: form.values,
|
||||||
});
|
});
|
||||||
history.push('/admin');
|
history.push(redirect || '/admin');
|
||||||
localStorage.setItem('NOCOBASE_TOKEN', data?.data?.token);
|
localStorage.setItem('NOCOBASE_TOKEN', data?.data?.token);
|
||||||
console.log('NOCOBASE_TOKEN', data?.data?.token);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user