Skip to content

Commit dbcc80c

Browse files
committed
fix: Login page check auth token
Fix utils getCookie
1 parent f747256 commit dbcc80c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/pages/Login/index.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import styles from './index.scss';
1818
}))
1919
@observer
2020
export default class Login extends Component {
21+
constructor(props) {
22+
super(props);
23+
24+
// eslint-disable-next-line
25+
if (_getUser().accessToken) {
26+
props.history.replace('/');
27+
}
28+
}
29+
2130
handleSubmit = async params => {
2231
const { store, user, history } = this.props;
2332
const res = await store.oauth2Check(params);

src/utils/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ export function setCookie(name, value, time) {
3838
}
3939

4040
export function getCookie(name) {
41-
const re = new RegExp(`${name}=([^;]+)`);
42-
const value = re.exec(document.cookie);
43-
return value !== null ? decodeURIComponent(value[1]) : null;
41+
const cookieMap = _.fromPairs(
42+
document.cookie.split(';').map(item => item.trim().split('='))
43+
);
44+
if (cookieMap[name]) {
45+
return decodeURIComponent(cookieMap[name]);
46+
}
47+
return null;
4448
}
4549

4650
export function getPastTime(time) {

0 commit comments

Comments
 (0)