Skip to content

Commit

Permalink
feat: 🎸 Clear personal cache on login and logout (kolplattformen#572)
Browse files Browse the repository at this point in the history
Until we have a better cache-clearing function in hooks lib this will
help with not filling the phone with old data
  • Loading branch information
whyer authored Dec 2, 2021
1 parent 933a884 commit bf29ab5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions apps/skolplattformen-app/components/login.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
PersonIcon,
SelectIcon,
} from './icon.component'
import AppStorage from '../services/appStorage'

const BankId = () => (
<Image
Expand Down Expand Up @@ -88,6 +89,8 @@ export const Login = () => {
] as const

const loginHandler = async () => {
const user = await api.getUser()
await AppStorage.clearPersonalData(user)
showModal(false)
}

Expand Down
6 changes: 4 additions & 2 deletions apps/skolplattformen-app/components/settings.component.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf29ab5

Please sign in to comment.