Update auth provider

This commit is contained in:
Dawid Tarasiuk 2020-07-15 16:09:12 +02:00 committed by dominik-zeglen
parent dd4022dcd7
commit d203a26bde

View file

@ -65,15 +65,6 @@ const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
}
};
useEffect(() => {
const token = getAuthToken();
if (!!token && !userContext) {
verifyToken(token);
} else {
loginWithCredentialsManagementAPI(login);
}
}, []);
useEffect(() => {
if (tokenAuthOpts.error || tokenVerifyOpts.error) {
logout();
@ -98,6 +89,15 @@ const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
}
}, [tokenAuthOpts, tokenVerifyOpts]);
useEffect(() => {
const token = getAuthToken();
if (!!token && !userContext) {
verifyToken(token);
} else {
loginWithCredentialsManagementAPI(login);
}
}, []);
const login = async (email: string, password: string) => {
tokenAuth({ variables: { email, password } }).then(result => {
if (result && !result.data.tokenCreate.errors.length) {