fixed missing account reset lost in refactor

This commit is contained in:
Roland Osborne 2023-04-03 21:23:47 -07:00
parent 2def0c1ee2
commit 25d437c046

View File

@ -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 };
}