Commit 9347b7a 1 parent 44e6112 commit 9347b7a Copy full SHA for 9347b7a
File tree 1 file changed +23
-6
lines changed
1 file changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -2,26 +2,43 @@ import type { Mastodon } from "megalodon";
2
2
import type { InstanceWithExtra } from "./Instance" ;
3
3
4
4
export const useCacheRefresh = ( client : MaybeRef < Mastodon | null > ) => {
5
+ if ( process . server ) return ;
6
+
5
7
const tokenData = useTokenData ( ) ;
6
8
const me = useMe ( ) ;
7
9
const instance = useInstance ( ) ;
8
10
const customEmojis = useCustomEmojis ( ) ;
9
11
10
12
// Refresh custom emojis and instance data and me on every reload
11
13
watchEffect ( async ( ) => {
14
+ console . log ( "Clearing cache" ) ;
12
15
if ( tokenData . value ) {
13
16
await toValue ( client )
14
17
?. verifyAccountCredentials ( )
15
18
. then ( ( res ) => {
16
19
me . value = res . data ;
20
+ } )
21
+ . catch ( ( err ) => {
22
+ const code = err . response . status ;
23
+
24
+ if ( code === 401 ) {
25
+ // Reset tokenData
26
+ tokenData . value = null ;
27
+ useEvent ( "notification:new" , {
28
+ type : "error" ,
29
+ title : "Your session has expired" ,
30
+ message :
31
+ "You have been logged out. Please log in again." ,
32
+ } ) ;
33
+ }
17
34
} ) ;
18
- }
19
35
20
- toValue ( client )
21
- ?. getInstanceCustomEmojis ( )
22
- . then ( ( res ) => {
23
- customEmojis . value = res . data ;
24
- } ) ;
36
+ await toValue ( client )
37
+ ?. getInstanceCustomEmojis ( )
38
+ . then ( ( res ) => {
39
+ customEmojis . value = res . data ;
40
+ } ) ;
41
+ }
25
42
26
43
toValue ( client )
27
44
?. getInstance ( )
You can’t perform that action at this time.
0 commit comments