feat: save login token
This commit is contained in:
parent
dc944060e1
commit
de8820eada
3 changed files with 6 additions and 6 deletions
|
@ -39,6 +39,7 @@ import { useFocusEffect, useNavigation } from '@react-navigation/native';
|
||||||
import { TabRoutes } from '../../navigation/TabNavigator';
|
import { TabRoutes } from '../../navigation/TabNavigator';
|
||||||
import { useShouldShowMascot } from '../../context/preferencesContext';
|
import { useShouldShowMascot } from '../../context/preferencesContext';
|
||||||
import { useLogin } from '../../context/loginContext';
|
import { useLogin } from '../../context/loginContext';
|
||||||
|
import { saveLoginToken } from '../../utils/loginToken';
|
||||||
|
|
||||||
type Props = StackScreenProps<MainStackParamsList, MainRoutes.Login>;
|
type Props = StackScreenProps<MainStackParamsList, MainRoutes.Login>;
|
||||||
|
|
||||||
|
@ -100,6 +101,7 @@ function LoginScreen(props: Props) {
|
||||||
if (homeMascot.shouldShow) {
|
if (homeMascot.shouldShow) {
|
||||||
homeMascot.setShouldShow(false);
|
homeMascot.setShouldShow(false);
|
||||||
}
|
}
|
||||||
|
saveLoginToken(token);
|
||||||
setLogin(token);
|
setLogin(token);
|
||||||
if (!nextScreen) {
|
if (!nextScreen) {
|
||||||
navigation.goBack();
|
navigation.goBack();
|
||||||
|
|
|
@ -21,16 +21,12 @@ export async function retrieveLoginToken(): Promise<string | undefined> {
|
||||||
/**
|
/**
|
||||||
* Saves the login token in the secure keychain
|
* Saves the login token in the secure keychain
|
||||||
*
|
*
|
||||||
* @param email
|
|
||||||
* @param token
|
* @param token
|
||||||
* @returns Promise<void>
|
* @returns Promise<void>
|
||||||
*/
|
*/
|
||||||
export async function saveLoginToken(
|
export async function saveLoginToken(token: string): Promise<void> {
|
||||||
email: string,
|
|
||||||
token: string
|
|
||||||
): Promise<void> {
|
|
||||||
return new Promise((resolve: () => void, reject: () => 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 { useCallback } from 'react';
|
||||||
import { useLogin } from '../context/loginContext';
|
import { useLogin } from '../context/loginContext';
|
||||||
|
import { deleteLoginToken } from './loginToken';
|
||||||
|
|
||||||
export const useLogout = () => {
|
export const useLogout = () => {
|
||||||
const { setLogin } = useLogin();
|
const { setLogin } = useLogin();
|
||||||
|
|
||||||
const onLogout = useCallback(() => {
|
const onLogout = useCallback(() => {
|
||||||
|
deleteLoginToken();
|
||||||
setLogin(undefined);
|
setLogin(undefined);
|
||||||
}, [setLogin]);
|
}, [setLogin]);
|
||||||
return onLogout;
|
return onLogout;
|
||||||
|
|
Loading…
Reference in a new issue