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) => {
295
295
< 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" />
296
296
</ svg >
297
297
</ Button >
298
- { /* <Button
298
+ < Button
299
299
fullWidth
300
300
id = "SignInWithGithub"
301
301
variant = "contained"
@@ -318,7 +318,7 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = (props) => {
318
318
>
319
319
< 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" />
320
320
</ svg >
321
- </Button>*/ }
321
+ </ Button >
322
322
< Button
323
323
fullWidth
324
324
variant = "contained"
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ return (
63
63
< Route
64
64
{ ...rest }
65
65
render = { ( props ) => {
66
- if ( isLoggedIn ) {
66
+ if ( isLoggedIn === true ) {
67
67
console . log ( "should be app" )
68
68
// User is logged in, render the protected component
69
69
return < Component { ...props } /> ;
Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ const cookieController: CookieController = {
12
12
//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
13
13
14
14
} ) ;
15
+
16
+ res . cookie ( 'username' , res . locals . username , {
17
+ httpOnly : true ,
18
+ sameSite : 'none' ,
19
+ secure : true ,
20
+ } ) ;
15
21
return next ( ) ;
16
22
} ,
17
23
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ const sessionController: SessionController = {
26
26
if ( ! session ) {
27
27
console . log ( 'no session' )
28
28
res . locals . loggedIn = false ;
29
- return res . redirect ( '/' ) ;
29
+ return next ( ) ;
30
+ // return res.redirect('/');
30
31
}
31
32
res . locals . loggedIn = true ;
32
33
return next ( ) ;
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ const Schema = mongoose.Schema;
3
3
4
4
const userSchema = new Schema ( {
5
5
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 }
8
8
} ) ;
9
9
10
10
const User = mongoose . model ( 'OauthUsers' , userSchema ) ;
Original file line number Diff line number Diff line change @@ -26,10 +26,21 @@ router.get(
26
26
router . get (
27
27
'/github/callback' ,
28
28
passport . authenticate ( 'github' ) ,
29
+ sessionController . startSession ,
29
30
( req : UserReq , res ) => {
30
- console . log ( 'this authenticate function is being run' ) ;
31
+ console . log ( 'github authenticate function is being run' ) ;
31
32
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
+ } ) ;
33
44
return res . redirect ( API_BASE_URL ) ;
34
45
}
35
46
) ;
@@ -39,19 +50,24 @@ router.get(
39
50
passport . authenticate ( 'google' , {
40
51
scope : [ 'profile' ]
41
52
} )
53
+
42
54
) ;
43
55
44
56
router . get (
45
57
'/google/callback' ,
46
58
passport . authenticate ( 'google' ) ,
47
59
sessionController . startSession ,
48
60
( req : UserReq , res ) => {
61
+
49
62
console . log ( 'google authenicate function being run' ) ;
50
63
res . cookie ( 'ssid' , req . user . id , {
51
64
httpOnly : true ,
52
65
sameSite : 'none' ,
53
66
secure : true ,
54
67
} ) ;
68
+
69
+
70
+
55
71
res . cookie ( 'username' , req . user . username , {
56
72
httpOnly : true ,
57
73
sameSite : 'none' ,
Original file line number Diff line number Diff line change @@ -36,9 +36,11 @@ passport.use(
36
36
console . log ( 'user is: ' , currentUser ) ;
37
37
return done ( null , currentUser ) ;
38
38
} else {
39
+ const initials = profile . displayName . match ( / \b \w / g) . join ( '' ) ;
40
+ const nums = profile . id . slice ( 0 , 5 ) ;
39
41
user
40
42
. create ( {
41
- username : profile . displayName + '(Github)' ,
43
+ username : initials + nums + '(Github)' ,
42
44
githubId : profile . id
43
45
} )
44
46
. then ( ( data ) => {
@@ -73,9 +75,11 @@ passport.use(
73
75
console . log ( 'user is: ' , currentUser ) ;
74
76
return done ( null , currentUser ) ;
75
77
} else {
78
+ const initials = profile . displayName . match ( / \b \w / g) . join ( '' ) ;
79
+ const nums = profile . id . slice ( 0 , 5 ) ;
76
80
user
77
81
. create ( {
78
- username : profile . displayName + '(Google)' ,
82
+ username : initials + nums + '(Google)' ,
79
83
googleId : profile . id
80
84
} )
81
85
. then ( ( data ) => {
Original file line number Diff line number Diff line change @@ -172,6 +172,19 @@ app.post(
172
172
( req , res ) => res . status ( 200 ) . json ( { sessionId : res . locals . ssid } )
173
173
) ;
174
174
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
+
175
188
// user must be logged in to get or save projects, otherwise they will be redirected to login page
176
189
app . post (
177
190
'/saveProject' ,
@@ -180,12 +193,6 @@ app.post(
180
193
( req , res ) => res . status ( 200 ) . json ( res . locals . savedProject )
181
194
) ;
182
195
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
- )
189
196
190
197
app . post (
191
198
'/getProjects' ,
You can’t perform that action at this time.
0 commit comments