atdalīts no vergnet/application-amicale
feat: save login token
Šī revīzija ir iekļauta:
vecāks
dc944060e1
revīzija
de8820eada
3 mainīti faili ar 6 papildinājumiem un 6 dzēšanām
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Notiek ielāde…
Atsaukties uz šo jaunā problēmā