File tree Expand file tree Collapse file tree 4 files changed +1216
-2109
lines changed Expand file tree Collapse file tree 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(
1212 static async getInitialProps ( ctx ) {
1313 // console.log('withAuth.getInitialProps');
1414 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 ;
1616
1717 if ( isFromServer && user ) {
1818 user . _id = user . _id . toString ( ) ;
@@ -39,12 +39,17 @@ export default function withAuth(
3939 return ;
4040 }
4141
42- if ( adminRequired && ( ! user || ! user . isAdmin ) ) {
42+ if ( adminRequired && user && ! user . isAdmin ) {
4343 Router . push ( '/customer/my-books' , '/my-books' ) ;
4444 }
4545
4646 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' ) ;
4853 }
4954 }
5055
@@ -55,7 +60,7 @@ export default function withAuth(
5560 return null ;
5661 }
5762
58- if ( adminRequired && ( ! user || ! user . isAdmin ) ) {
63+ if ( adminRequired && user && ! user . isAdmin ) {
5964 return null ;
6065 }
6166
Original file line number Diff line number Diff line change 1717 "coverageDirectory" : " ./.coverage"
1818 },
1919 "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" ,
2222 "@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 " ,
2626 "@octokit/oauth-authorization-url" : " ^4.1.0" ,
2727 "@octokit/rest" : " ^18.0.3" ,
2828 "@stripe/stripe-js" : " ^1.21.1" ,
4040 "lodash" : " ^4.17.21" ,
4141 "marked" : " ^1.2.7" ,
4242 "mongoose" : " ^5.10.0" ,
43- "next" : " ^12.0.3 " ,
43+ "next" : " ^12.1.6 " ,
4444 "node-fetch" : " ^2.6.1" ,
4545 "nprogress" : " ^0.2.0" ,
46- "passport" : " ^0.4.1 " ,
46+ "passport" : " ^0.6.0 " ,
4747 "passport-google-oauth" : " ^2.0.0" ,
4848 "prop-types" : " ^15.7.2" ,
4949 "qs" : " ^6.10.1" ,
Original file line number Diff line number Diff line change @@ -84,17 +84,21 @@ function setupGoogle({ server, ROOT_URL }) {
8484
8585 if ( req . user && req . user . isAdmin ) {
8686 res . redirect ( '/admin' ) ;
87- } else if ( req . session . finalUrl ) {
87+ } else if ( req . user && req . session . finalUrl ) {
8888 res . redirect ( `${ ROOT_URL } ${ req . session . finalUrl } ` ) ;
8989 } else {
9090 res . redirect ( '/my-books' ) ;
9191 }
9292 } ,
9393 ) ;
9494
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+ } ) ;
98102 } ) ;
99103}
100104
You can’t perform that action at this time.
0 commit comments