mirror of
https://github.com/balzack/databag.git
synced 2025-04-20 16:45:25 +00:00
fixed missing account reset lost in refactor
This commit is contained in:
parent
2def0c1ee2
commit
25d437c046
@ -1,7 +1,7 @@
|
||||
import { useContext, useState, useEffect } from 'react';
|
||||
import { AppContext } from 'context/AppContext';
|
||||
import { getAvailable } from 'api/getAvailable';
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
|
||||
export function useLogin() {
|
||||
|
||||
@ -14,6 +14,7 @@ export function useLogin() {
|
||||
});
|
||||
|
||||
const navigate = useNavigate();
|
||||
const { search } = useLocation();
|
||||
const app = useContext(AppContext);
|
||||
|
||||
const updateState = (value) => {
|
||||
@ -69,6 +70,29 @@ export function useLogin() {
|
||||
// eslint-disable-next-line
|
||||
}, [])
|
||||
|
||||
const access = async (token) => {
|
||||
if (!state.busy) {
|
||||
updateState({ busy: true });
|
||||
try {
|
||||
await app.actions.access(token);
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
updateState({ busy: false });
|
||||
throw new Error('access failed: check your token');
|
||||
}
|
||||
updateState({ busy: false });
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
let params = new URLSearchParams(search);
|
||||
let token = params.get("access");
|
||||
if (token) {
|
||||
access(token);
|
||||
}
|
||||
}, [])
|
||||
|
||||
return { state, actions };
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user