feat: save login token

Šī revīzija ir iekļauta:
Arnaud Vergnet 2021-09-12 23:39:23 +02:00
vecāks dc944060e1
revīzija de8820eada
3 mainīti faili ar 6 papildinājumiem un 6 dzēšanām

Parādīt failu

@ -39,6 +39,7 @@ import { useFocusEffect, useNavigation } from '@react-navigation/native';
import { TabRoutes } from '../../navigation/TabNavigator';
import { useShouldShowMascot } from '../../context/preferencesContext';
import { useLogin } from '../../context/loginContext';
import { saveLoginToken } from '../../utils/loginToken';
type Props = StackScreenProps<MainStackParamsList, MainRoutes.Login>;
@ -100,6 +101,7 @@ function LoginScreen(props: Props) {
if (homeMascot.shouldShow) {
homeMascot.setShouldShow(false);
}
saveLoginToken(token);
setLogin(token);
if (!nextScreen) {
navigation.goBack();

Parādīt failu

@ -21,16 +21,12 @@ export async function retrieveLoginToken(): Promise<string | undefined> {
/**
* Saves the login token in the secure keychain
*
* @param email
* @param token
* @returns Promise<void>
*/
export async function saveLoginToken(
email: string,
token: string
): Promise<void> {
export async function saveLoginToken(token: string): Promise<void> {
return new Promise((resolve: () => void, reject: () => void) => {
Keychain.setGenericPassword(email, token).then(resolve).catch(reject);
Keychain.setGenericPassword('amicale', token).then(resolve).catch(reject);
});
}

Parādīt failu

@ -1,10 +1,12 @@
import { useCallback } from 'react';
import { useLogin } from '../context/loginContext';
import { deleteLoginToken } from './loginToken';
export const useLogout = () => {
const { setLogin } = useLogin();
const onLogout = useCallback(() => {
deleteLoginToken();
setLogin(undefined);
}, [setLogin]);
return onLogout;