File tree Expand file tree Collapse file tree 8 files changed +50
-16
lines changed Expand file tree Collapse file tree 8 files changed +50
-16
lines changed Original file line number Diff line number Diff line change @@ -295,7 +295,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = (props) => {
295295 < path d = "M8.256 14a4.474 4.474 0 0 1-.229-1.004H3c.001-.246.154-.986.832-1.664C4.484 10.68 5.711 10 8 10c.26 0 .507.009.74.025.226-.341.496-.65.804-.918C9.077 9.038 8.564 9 8 9c-5 0-6 3-6 4s1 1 1 1h5.256Z" />
296296 </ svg >
297297 </ Button >
298- { /* <Button
298+ < Button
299299 fullWidth
300300 id = "SignInWithGithub"
301301 variant = "contained"
@@ -318,7 +318,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = (props) => {
318318 >
319319 < path d = "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z" />
320320 </ svg >
321- </Button>*/ }
321+ </ Button >
322322 < Button
323323 fullWidth
324324 variant = "contained"
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ return (
6363 < Route
6464 { ...rest }
6565 render = { ( props ) => {
66- if ( isLoggedIn ) {
66+ if ( isLoggedIn === true ) {
6767 console . log ( "should be app" )
6868 // User is logged in, render the protected component
6969 return < Component { ...props } /> ;
Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ const cookieController: CookieController = {
1212 //maxAge: 60 * 60 * 1000 * 24 //uncomment to set expiration of cookies, but make sure there is something in place to expire local storage info too
1313
1414 } ) ;
15+
16+ res . cookie ( 'username' , res . locals . username , {
17+ httpOnly : true ,
18+ sameSite : 'none' ,
19+ secure : true ,
20+ } ) ;
1521 return next ( ) ;
1622 } ,
1723
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ const sessionController: SessionController = {
2626 if ( ! session ) {
2727 console . log ( 'no session' )
2828 res . locals . loggedIn = false ;
29- return res . redirect ( '/' ) ;
29+ return next ( ) ;
30+ // return res.redirect('/');
3031 }
3132 res . locals . loggedIn = true ;
3233 return next ( ) ;
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ const Schema = mongoose.Schema;
33
44const userSchema = new Schema ( {
55 username : { type : String } ,
6- githubId : { type : String , unique : false } ,
7- googleId : { type : String , unique : false }
6+ githubId : { type : String , unique : true } ,
7+ googleId : { type : String , unique : true }
88} ) ;
99
1010const User = mongoose . model ( 'OauthUsers' , userSchema ) ;
Original file line number Diff line number Diff line change @@ -26,10 +26,21 @@ router.get(
2626router . get (
2727 '/github/callback' ,
2828 passport . authenticate ( 'github' ) ,
29+ sessionController . startSession ,
2930 ( req : UserReq , res ) => {
30- console . log ( 'this authenticate function is being run' ) ;
31+ console . log ( 'github authenticate function is being run' ) ;
3132 console . log ( req . user . id ) ;
32- res . cookie ( 'ssid' , req . user . id ) ;
33+ res . cookie ( 'ssid' , req . user . id , {
34+ httpOnly : true ,
35+ sameSite : 'none' ,
36+ secure : true ,
37+ } ) ;
38+
39+ res . cookie ( 'username' , req . user . username , {
40+ httpOnly : true ,
41+ sameSite : 'none' ,
42+ secure : true ,
43+ } ) ;
3344 return res . redirect ( API_BASE_URL ) ;
3445 }
3546) ;
@@ -39,19 +50,24 @@ router.get(
3950 passport . authenticate ( 'google' , {
4051 scope : [ 'profile' ]
4152 } )
53+
4254) ;
4355
4456router . get (
4557 '/google/callback' ,
4658 passport . authenticate ( 'google' ) ,
4759 sessionController . startSession ,
4860 ( req : UserReq , res ) => {
61+
4962 console . log ( 'google authenicate function being run' ) ;
5063 res . cookie ( 'ssid' , req . user . id , {
5164 httpOnly : true ,
5265 sameSite : 'none' ,
5366 secure : true ,
5467 } ) ;
68+
69+
70+
5571 res . cookie ( 'username' , req . user . username , {
5672 httpOnly : true ,
5773 sameSite : 'none' ,
Original file line number Diff line number Diff line change @@ -36,9 +36,11 @@ passport.use(
3636 console . log ( 'user is: ' , currentUser ) ;
3737 return done ( null , currentUser ) ;
3838 } else {
39+ const initials = profile . displayName . match ( / \b \w / g) . join ( '' ) ;
40+ const nums = profile . id . slice ( 0 , 5 ) ;
3941 user
4042 . create ( {
41- username : profile . displayName + '(Github)' ,
43+ username : initials + nums + '(Github)' ,
4244 githubId : profile . id
4345 } )
4446 . then ( ( data ) => {
@@ -73,9 +75,11 @@ passport.use(
7375 console . log ( 'user is: ' , currentUser ) ;
7476 return done ( null , currentUser ) ;
7577 } else {
78+ const initials = profile . displayName . match ( / \b \w / g) . join ( '' ) ;
79+ const nums = profile . id . slice ( 0 , 5 ) ;
7680 user
7781 . create ( {
78- username : profile . displayName + '(Google)' ,
82+ username : initials + nums + '(Google)' ,
7983 googleId : profile . id
8084 } )
8185 . then ( ( data ) => {
Original file line number Diff line number Diff line change @@ -172,6 +172,19 @@ app.post(
172172 ( req , res ) => res . status ( 200 ) . json ( { sessionId : res . locals . ssid } )
173173) ;
174174
175+ //confirming whether user is logged in for index.tsx rendering
176+ app . get (
177+ '/loggedIn' ,
178+ sessionController . isLoggedIn ,
179+ ( req , res ) => res . status ( 200 ) . json ( res . locals . loggedIn )
180+ )
181+
182+ app . get ( '/logout' , ( req , res ) => {
183+
184+ req . logout ( ) ;
185+ res . redirect ( '/login' ) ;
186+ } )
187+
175188// user must be logged in to get or save projects, otherwise they will be redirected to login page
176189app . post (
177190 '/saveProject' ,
@@ -180,12 +193,6 @@ app.post(
180193 ( req , res ) => res . status ( 200 ) . json ( res . locals . savedProject )
181194) ;
182195
183- //confirming whether user is logged in for index.tsx rendering
184- app . get (
185- '/loggedIn' ,
186- sessionController . isLoggedIn ,
187- ( req , res ) => res . status ( 200 ) . json ( res . locals . loggedIn )
188- )
189196
190197app . post (
191198 '/getProjects' ,
You can’t perform that action at this time.
0 commit comments