File tree 9 files changed +61
-94
lines changed
9 files changed +61
-94
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ VUE_APP_SELF_HOST=https://web-tech.tw/openchat
2
2
VUE_APP_OCJI_HOST = https://web-tech.tw/recv/openchat
3
3
4
4
VUE_APP_SARA_INTE_HOST = https://web-tech.tw/sara
5
- VUE_APP_SARA_RECV_HOST = https://web-tech.tw/recv/sara
6
5
VUE_APP_SARA_TOKEN_NAME = unified_token
7
6
8
7
VUE_APP_TURNSTILE_SITE_KEY = " 0x4AAAAAAAr6LY1hBUbTBkVA"
Original file line number Diff line number Diff line change 12
12
"autoprefixer" : " ^10" ,
13
13
"core-js" : " ^3.8.3" ,
14
14
"dayjs" : " ^1.11.12" ,
15
+ "jwt-decode" : " ^4.0.0" ,
15
16
"nanoid" : " ^5.0.7" ,
16
17
"postcss" : " ^8" ,
17
18
"tailwindcss" : " ^3" ,
Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ export default {
237
237
},
238
238
async created () {
239
239
document .addEventListener (' click' , this .handleDocumentClick );
240
- this .profile = await this .$profile ();
240
+ this .profile = this .$profile ();
241
241
},
242
242
methods: {
243
243
openMenu (item ) {
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
- import './plugins/sara'
3
2
import './plugins/axios'
3
+ import './plugins/profile'
4
4
import App from './App.vue'
5
5
import router from './router'
6
6
import './assets/tailwind.css'
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ import Vue from "vue" ;
4
+ import { jwtDecode } from "jwt-decode" ;
5
+
6
+ const {
7
+ VUE_APP_SARA_TOKEN_NAME : saraTokenName ,
8
+ } = process . env ;
9
+
10
+ export const useProfile = ( ) => {
11
+ const saraToken = localStorage . getItem ( saraTokenName ) ;
12
+ if ( ! saraToken ) {
13
+ return null ;
14
+ }
15
+
16
+ try {
17
+ const data = jwtDecode ( saraToken ) ;
18
+ if ( Date . now ( ) >= data . exp * 1000 ) {
19
+ throw new Error ( "sara token expired" ) ;
20
+ }
21
+ return data ?. user ;
22
+ } catch ( e ) {
23
+ console . warn ( e ) ;
24
+ localStorage . removeItem ( saraTokenName ) ;
25
+ location . reload ( ) ;
26
+ return null ;
27
+ }
28
+ } ;
29
+
30
+ const extension = {
31
+ install : ( Vue ) => {
32
+ window . profile = useProfile ;
33
+ Vue . profile = useProfile ;
34
+ Vue . prototype . profile = useProfile ;
35
+ Vue . prototype . $profile = useProfile ;
36
+ } ,
37
+ } ;
38
+
39
+ Vue . use ( extension ) ;
40
+
41
+ export default extension ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ export default {
176
176
},
177
177
},
178
178
async created () {
179
- this .profile = await this .$profile ();
179
+ this .profile = this .$profile ();
180
180
if (! this .profile ) {
181
181
const refer = ` ${ process .env .VUE_APP_SELF_HOST } /#/admin/join` ;
182
182
const url = ` ${ process .env .VUE_APP_SARA_INTE_HOST } /?refer=${ encodeURIComponent (refer)} ` ;
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ export default {
62
62
},
63
63
},
64
64
async created () {
65
- this .profile = await this .$profile ();
65
+ this .profile = this .$profile ();
66
66
if (! this .profile ) {
67
67
const refer = ` ${ process .env .VUE_APP_SELF_HOST } /#/admin/room` ;
68
68
const url = ` ${ process .env .VUE_APP_SARA_INTE_HOST } /?refer=${ encodeURIComponent (refer)} ` ;
You can’t perform that action at this time.
0 commit comments