Commit f1a86d5 1 parent adcb75a commit f1a86d5 Copy full SHA for f1a86d5
File tree 2 files changed +21
-4
lines changed
2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,21 @@ function syncArtalk(artalk: Artalk) {
48
48
const artalkUser = artalk .ctx .get (' user' )
49
49
const artalkUserData = artalkUser .getData ()
50
50
51
+ const logout = () => {
52
+ user .logout ()
53
+ nextTick (() => {
54
+ router .replace (' /login' )
55
+ })
56
+ }
57
+
58
+ // Remove login failed dialog if sidebar
59
+ artalk .ctx .getApiHandlers ().remove (' need_login' )
60
+ artalk .ctx .getApiHandlers ().add (' need_login' , async () => {
61
+ logout ()
62
+ throw new Error (' Need login' )
63
+ })
64
+
65
+ // Check user status
51
66
artalk .ctx
52
67
.getApi ()
53
68
.user .getUserStatus ({
@@ -56,10 +71,7 @@ function syncArtalk(artalk: Artalk) {
56
71
})
57
72
.then ((res ) => {
58
73
if (res .data .is_admin && ! res .data .is_login ) {
59
- user .logout ()
60
- nextTick (() => {
61
- router .replace (' /login' )
62
- })
74
+ logout ()
63
75
} else {
64
76
// 将全部通知标记为已读
65
77
artalk .ctx .getApi ().notifies .markAllNotifyRead ({
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ export interface ApiHandlers {
16
16
action : T ,
17
17
handler : ( data : ApiHandlerPayload [ T ] ) => Promise < void > ,
18
18
) => void
19
+ remove : ( action : PayloadKey ) => void
19
20
get : ( ) => ApiHandler [ ]
20
21
}
21
22
@@ -25,6 +26,10 @@ export function createApiHandlers(): ApiHandlers {
25
26
add : ( action , handler ) => {
26
27
handlers . push ( { action, handler } )
27
28
} ,
29
+ remove : ( action ) => {
30
+ const index = handlers . findIndex ( ( h ) => h . action === action )
31
+ if ( index !== - 1 ) handlers . splice ( index , 1 )
32
+ } ,
28
33
get : ( ) => handlers ,
29
34
}
30
35
}
You can’t perform that action at this time.
0 commit comments