feat: 🎸 Clear personal cache on login and logout (#572)

Until we have a better cache-clearing function in hooks lib this will
help with not filling the phone with old data
This commit is contained in:
Andreas Eriksson 2021-12-02 15:37:52 +01:00 committed by GitHub
parent 933a8840a3
commit bf29ab58ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -34,6 +34,7 @@ import {
PersonIcon,
SelectIcon,
} from './icon.component'
import AppStorage from '../services/appStorage'
const BankId = () => (
<Image
@ -88,6 +89,8 @@ export const Login = () => {
] as const
const loginHandler = async () => {
const user = await api.getUser()
await AppStorage.clearPersonalData(user)
showModal(false)
}

View File

@ -1,5 +1,5 @@
import { NavigationProp, useNavigation } from '@react-navigation/core'
import { useApi } from '@skolplattformen/hooks'
import { useApi, useUser } from '@skolplattformen/hooks'
import React, { useCallback } from 'react'
import { ScrollView } from 'react-native'
import { NativeStackNavigationOptions } from 'react-native-screens/native-stack'
@ -28,14 +28,16 @@ export const SettingsScreen = () => {
const langCode = LanguageService.getLanguageCode()
const language = languages.find((l) => l.langCode === langCode)
const { api } = useApi()
const { data: user } = useUser()
const logout = useCallback(async () => {
await AppStorage.clearTemporaryItems()
await AppStorage.clearPersonalData(user)
await api.logout()
navigation.reset({
routes: [{ name: 'Login' }],
})
}, [api, navigation])
}, [api, navigation, user])
return (
<ScrollView