File tree 4 files changed +1216
-2109
lines changed
4 files changed +1216
-2109
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export default function withAuth(
12
12
static async getInitialProps ( ctx ) {
13
13
// console.log('withAuth.getInitialProps');
14
14
const isFromServer = typeof window === 'undefined' ;
15
- const user = ctx . req ? ctx . req . user && ctx . req . user . toObject ( ) : globalUser ;
15
+ const user = ctx . req ? ctx . req . user : globalUser ;
16
16
17
17
if ( isFromServer && user ) {
18
18
user . _id = user . _id . toString ( ) ;
@@ -39,12 +39,17 @@ export default function withAuth(
39
39
return ;
40
40
}
41
41
42
- if ( adminRequired && ( ! user || ! user . isAdmin ) ) {
42
+ if ( adminRequired && user && ! user . isAdmin ) {
43
43
Router . push ( '/customer/my-books' , '/my-books' ) ;
44
44
}
45
45
46
46
if ( logoutRequired && user ) {
47
- Router . push ( '/' ) ;
47
+ if ( ! user . isAdmin ) {
48
+ Router . push ( '/customer/my-books' , '/my-books' ) ;
49
+ return ;
50
+ }
51
+
52
+ Router . push ( '/admin' ) ;
48
53
}
49
54
}
50
55
@@ -55,7 +60,7 @@ export default function withAuth(
55
60
return null ;
56
61
}
57
62
58
- if ( adminRequired && ( ! user || ! user . isAdmin ) ) {
63
+ if ( adminRequired && user && ! user . isAdmin ) {
59
64
return null ;
60
65
}
61
66
Original file line number Diff line number Diff line change 17
17
"coverageDirectory" : " ./.coverage"
18
18
},
19
19
"dependencies" : {
20
- "@emotion/cache" : " ^11.6.0 " ,
21
- "@emotion/react" : " ^11.6 .0" ,
20
+ "@emotion/cache" : " ^11.7.1 " ,
21
+ "@emotion/react" : " ^11.9 .0" ,
22
22
"@emotion/server" : " ^11.4.0" ,
23
- "@emotion/styled" : " ^11.6.0 " ,
24
- "@mui/icons-material" : " ^5.2.0 " ,
25
- "@mui/material" : " ^5.2.0 " ,
23
+ "@emotion/styled" : " ^11.8.1 " ,
24
+ "@mui/icons-material" : " ^5.8.3 " ,
25
+ "@mui/material" : " ^5.8.3 " ,
26
26
"@octokit/oauth-authorization-url" : " ^4.1.0" ,
27
27
"@octokit/rest" : " ^18.0.3" ,
28
28
"@stripe/stripe-js" : " ^1.21.1" ,
40
40
"lodash" : " ^4.17.21" ,
41
41
"marked" : " ^1.2.7" ,
42
42
"mongoose" : " ^5.10.0" ,
43
- "next" : " ^12.0.3 " ,
43
+ "next" : " ^12.1.6 " ,
44
44
"node-fetch" : " ^2.6.1" ,
45
45
"nprogress" : " ^0.2.0" ,
46
- "passport" : " ^0.4.1 " ,
46
+ "passport" : " ^0.6.0 " ,
47
47
"passport-google-oauth" : " ^2.0.0" ,
48
48
"prop-types" : " ^15.7.2" ,
49
49
"qs" : " ^6.10.1" ,
Original file line number Diff line number Diff line change @@ -84,17 +84,21 @@ function setupGoogle({ server, ROOT_URL }) {
84
84
85
85
if ( req . user && req . user . isAdmin ) {
86
86
res . redirect ( '/admin' ) ;
87
- } else if ( req . session . finalUrl ) {
87
+ } else if ( req . user && req . session . finalUrl ) {
88
88
res . redirect ( `${ ROOT_URL } ${ req . session . finalUrl } ` ) ;
89
89
} else {
90
90
res . redirect ( '/my-books' ) ;
91
91
}
92
92
} ,
93
93
) ;
94
94
95
- server . get ( '/logout' , ( req , res ) => {
96
- req . logout ( ) ;
97
- res . redirect ( '/login' ) ;
95
+ server . get ( '/logout' , ( req , res , next ) => {
96
+ req . logout ( ( err ) => {
97
+ if ( err ) {
98
+ next ( err ) ;
99
+ }
100
+ res . redirect ( '/login' ) ;
101
+ } ) ;
98
102
} ) ;
99
103
}
100
104
You can’t perform that action at this time.
0 commit comments