File tree Expand file tree Collapse file tree 8 files changed +706
-112
lines changed Expand file tree Collapse file tree 8 files changed +706
-112
lines changed Original file line number Diff line number Diff line change 88
88
89
89
# Vim swap files
90
90
* .swp
91
+
92
+ .runtimeconfig.json
93
+ key.json
Original file line number Diff line number Diff line change @@ -63,6 +63,10 @@ module.exports = {
63
63
src : '@/plugins/persistedstate.js' ,
64
64
ssr : false ,
65
65
} ,
66
+ {
67
+ src : '@/plugins/firebase-admin.js' ,
68
+ ssr : true ,
69
+ } ,
66
70
] ,
67
71
/*
68
72
** Nuxt.js dev-modules
Original file line number Diff line number Diff line change 35
35
"dayjs" : " ^1.8.26" ,
36
36
"express" : " ^4.17.1" ,
37
37
"firebase" : " ^7.14.2" ,
38
+ "firebase-admin" : " ^8.12.0" ,
38
39
"js-cookie" : " ^2.2.1" ,
39
40
"jwt-decode" : " ^2.2.0" ,
40
41
"lodash.clonedeep" : " ^4.5.0" ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- export default function ( { store, redirect } ) {
2
- if ( ! store . getters [ 'modules/user/isAuthenticated' ] ) {
3
- return redirect ( '/account/login' )
1
+ export default ( { req, redirect } ) => {
2
+ if ( process . server ) {
3
+ const admin = require ( 'firebase-admin' )
4
+ const cookieparser = require ( 'cookieparser' )
5
+ if ( req . headers . cookie ) {
6
+ const token = cookieparser . parse ( req . headers . cookie ) . __session
7
+ admin
8
+ . auth ( )
9
+ . verifyIdToken ( token )
10
+ . then ( ( ) => { } )
11
+ . catch ( ( error ) => {
12
+ console . error ( error )
13
+ redirect ( '/account/login' )
14
+ } )
15
+ } else {
16
+ redirect ( '/account/login' )
17
+ }
4
18
}
5
19
}
Original file line number Diff line number Diff line change
1
+ // eslint-disable-next-line import/no-mutable-exports
2
+ let admin = null
3
+ if ( process . server ) {
4
+ admin = require ( 'firebase-admin' )
5
+ if ( ! admin . apps . length ) {
6
+ admin . initializeApp ( {
7
+ credential : admin . credential . applicationDefault ( ) ,
8
+ databaseURL : 'https://studyathome.firebaseio.com' ,
9
+ } )
10
+ }
11
+ }
12
+
13
+ // eslint-disable-next-line no-undef
14
+ export default admin
Original file line number Diff line number Diff line change @@ -32,15 +32,15 @@ export const actions = {
32
32
avatar : user . photoURL ,
33
33
uid : user . uid ,
34
34
}
35
- Cookies . set ( 'access_token ' , token ) // saving token in cookie for server rendering
35
+ Cookies . set ( '__session ' , token ) // saving token in cookie for server rendering
36
36
await dispatch ( 'setUserData' , userInfo )
37
37
await dispatch ( 'setUid' , firebase . auth ( ) . currentUser . uid )
38
38
} ,
39
39
40
40
async logout ( { commit } ) {
41
41
await firebase . auth ( ) . signOut ( )
42
42
43
- Cookies . remove ( 'access_token ' )
43
+ Cookies . remove ( '__session ' )
44
44
commit ( 'setUserData' , null )
45
45
commit ( 'setUid' , null )
46
46
} ,
You can’t perform that action at this time.
0 commit comments