feat: login redirect

This commit is contained in:
chenos 2021-08-23 22:21:40 +08:00
parent dd769e4d04
commit 44633db5ff
2 changed files with 7 additions and 4 deletions

View File

@ -1,3 +1,4 @@
import { Card } from 'antd';
import React from 'react';
import { useLocation, useHistory } from 'react-router-dom';
@ -5,7 +6,7 @@ export function AuthLayout({ children, route }: any) {
const location = useLocation();
const history = useHistory();
return (
<div style={{ maxWidth: 320, margin: '0 auto' }}>
<div style={{ maxWidth: 320, margin: '0 auto', paddingTop: '20vh' }}>
<h1>NocoBase</h1>
{children}
</div>

View File

@ -4,7 +4,7 @@ import { Helmet } from 'react-helmet';
import { useRequest } from 'ahooks';
import { request, SchemaRenderer } from '../../schemas';
import { useForm } from '@formily/react';
import { useHistory } from 'react-router-dom';
import { useHistory, useLocation } from 'react-router-dom';
function Div(props) {
return <div {...props}></div>;
@ -13,6 +13,9 @@ function Div(props) {
export function useLogin() {
const form = useForm();
const history = useHistory();
const location = useLocation<any>();
const query = new URLSearchParams(location.search);
const redirect = query.get('redirect');
return {
async run() {
await form.submit();
@ -20,9 +23,8 @@ export function useLogin() {
method: 'post',
data: form.values,
});
history.push('/admin');
history.push(redirect || '/admin');
localStorage.setItem('NOCOBASE_TOKEN', data?.data?.token);
console.log('NOCOBASE_TOKEN', data?.data?.token);
},
};
}