feat: align auth api with front convention (#370)

* feat: align auth api with front convention

* fix: email password auth

* fix: proper file naming

* Fix login

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Jérémy M
2023-06-24 07:43:54 +02:00
committed by GitHub
parent c6708b2c1f
commit 31145c5518
23 changed files with 222 additions and 293 deletions

View File

@ -3,11 +3,12 @@ import { useRecoilState } from 'recoil';
import { useChallengeMutation, useVerifyMutation } from '~/generated/graphql';
import { tokenService } from '../services/TokenService';
import { currentUserState } from '../states/currentUserState';
import { isAuthenticatingState } from '../states/isAuthenticatingState';
import { tokenPairState } from '../states/tokenPairState';
export function useAuth() {
const [, setTokenPair] = useRecoilState(tokenPairState);
const [, setCurrentUser] = useRecoilState(currentUserState);
const [, setIsAuthenticating] = useRecoilState(isAuthenticatingState);
@ -50,14 +51,14 @@ export function useAuth() {
throw new Error('No verify result');
}
tokenService.setTokenPair(verifyResult.data?.verify.tokens);
setTokenPair(verifyResult.data?.verify.tokens);
setIsAuthenticating(false);
setCurrentUser(verifyResult.data?.verify.user);
return verifyResult.data?.verify;
},
[setCurrentUser, setIsAuthenticating, verify],
[setCurrentUser, setIsAuthenticating, setTokenPair, verify],
);
const handleLogin = useCallback(
@ -70,8 +71,8 @@ export function useAuth() {
);
const handleLogout = useCallback(() => {
tokenService.removeTokenPair();
}, []);
setTokenPair(null);
}, [setTokenPair]);
return {
challenge: handleChallenge,