From b82638f247c029e7792a0e69c5856173108555c6 Mon Sep 17 00:00:00 2001 From: axolotle Date: Fri, 28 Jul 2023 17:30:56 +0200 Subject: [PATCH] use localeStorage to store isLoggedIn value --- composables/states.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/composables/states.ts b/composables/states.ts index 86480fb..290eb11 100644 --- a/composables/states.ts +++ b/composables/states.ts @@ -1,3 +1,17 @@ -export const useIsLoggedIn = () => useState('isLoggedIn', () => false) +export const useIsLoggedIn = () => { + const isLoggedIn = useState( + 'isLoggedIn', + () => localStorage.getItem('isLoggedIn') === 'true', + ) + + return computed({ + get: () => isLoggedIn.value, + set: (value) => { + isLoggedIn.value = value + localStorage.setItem('isLoggedIn', value.toString()) + }, + }) +} + export const useRedirectUrl = () => useState('redirectUrl', () => null)