Repository navigation
Conversation
timmyichen
left a comment
There was a problem hiding this comment.
Thanks for taking on this monster of a task! I left a few comments/questions. There are quite a few todos in comments - is this PR complete or did I jump the gun on reviewing?
|
|
||
| script.onload = () => { | ||
| const handleCredentialResponse = async (response: any) => { | ||
| console.log('handleCredentialResponse ', response); |
There was a problem hiding this comment.
console logs should be removed
| NEXT_PUBLIC_GOOGLE_API_KEY=<api key here> | ||
| # will need to be assigned new values on deployment | ||
| NEXT_PUBLIC_TOKEN_AUTH_URL=http://localhost:5000/auth/google/token | ||
| NEXT_PUBLIC_IS_AUTH_URL=http://localhost:5000/auth/is-auth/ No newline at end of file |
| GOOGLE_CLIENT_ID=id from applications dashboard | ||
| GOOGLE_CLIENT_SECRET=secret from applicaitons dashboard | ||
| # Will need to be changed for production | ||
| GOOGLE_REDIRECT_URI=http://localhost:5000/auth/google/callback No newline at end of file |
| NEXT_PUBLIC_TOKEN_AUTH_URL=http://localhost:5000/auth/google/token | ||
| NEXT_PUBLIC_IS_AUTH_URL=http://localhost:5000/auth/is-auth/ No newline at end of file |
There was a problem hiding this comment.
why do these need to be environment variables?
There was a problem hiding this comment.
Depending on deployment. I wasn't sure if the url for the api would change in production. If not, then I guess we could hardcode them.
There was a problem hiding this comment.
It should be relative regardless, right? Eg /auth/google/token should work regardless of what the host is
There was a problem hiding this comment.
Frontend is on 3000 and the server is on 5000, so I thought I needed to distinguish between the two.
There was a problem hiding this comment.
ahhhhhhhhhhhhh right. in that case, the client should just set like baseUrl to be whatever its meant to be, and then in the code it should just be ${baseUrl}/auth/google/token
although i don't know why they are separate (and don't agree with it), so i'll look to change that soon
| GOOGLE_CLIENT_ID=id from applications dashboard | ||
| GOOGLE_CLIENT_SECRET=secret from applicaitons dashboard | ||
| # Will need to be changed for production | ||
| GOOGLE_REDIRECT_URI=http://localhost:5000/auth/google/callback No newline at end of file |
There was a problem hiding this comment.
also - why does this need to be an environment variable?
There was a problem hiding this comment.
See my comment above about the other env vars.
| console.log('parsedToken ', parsedToken); | ||
| console.log('googleId ', googleId); |
There was a problem hiding this comment.
extraneous console logs
| @@ -0,0 +1,23 @@ | |||
| import express from 'express'; | |||
| import Setup from './google/passport'; | |||
| console.log('is there ', req.isAuthenticated()); | ||
| console.log('is there ', req.user); |
There was a problem hiding this comment.
extraneous console.logs
| const router = express.Router(); | ||
|
|
||
| router.use( | ||
| '/is-auth', // add { credentials: 'include' } into fetch request for this endpoint to work |
There was a problem hiding this comment.
would prefer this to be spelled, or at least add 'ed', out for clarity
| '/is-auth', // add { credentials: 'include' } into fetch request for this endpoint to work | |
| '/is-authed', // add { credentials: 'include' } into fetch request for this endpoint to work |
There was a problem hiding this comment.
I'll take care of this locally, then push so I can update the call as well
|
@timmyichen Do we happen to have a logging library already (I like loglevel personally), which should be used instead of |
not yet i don't think, though i'm not sure if one is needed. what use case were you thinking? we can take this into Discord or into an issue if it's not relevant to this PR |
|
Let's move it to #412, since it is outside the scope of this PR. |
@timmyichen It's almost there! The ui still needs some logic to prevent the one tap from loading and the google login from showing when you're logged in. Also, a logout endpoint needs to be created and connected to the ui. Should I add those changes to this pr or leave it for another one? Sorry about the extraneous logs btw. I'll handle those soon. |
No worries! Same PR makes sense, given it's a related feature and logging out shouldn't be that complex using passport (i think it's just |
f8e3ea8 to
a5a9e0a
Compare
timmyichen
left a comment
There was a problem hiding this comment.
Thanks again for taking this on! I left a few comments - there are a few older unaddressed comments as well. Please ping me if you have any questions.
| const responseBody = await response.json(); | ||
| const { isAuth } = responseBody; | ||
|
|
||
| if (!isAuth) { |
There was a problem hiding this comment.
isAuth will always be false in this hook because it's initialized to be false, and the hook only runs once on mount.
There was a problem hiding this comment.
This isAuth is refering to the api call in the func.
| if (headerLink.name === 'google' && !isAuth) { | ||
| return ( | ||
| <Grid item key={headerLink.name}> | ||
| <a className={styles.link} href={headerLink.href}> | ||
| {headerLink.label} | ||
| </a> | ||
| </Grid> | ||
| ); | ||
| } else if (headerLink.name === 'google' && isAuth) { | ||
| return null; | ||
| } | ||
|
|
||
| if (headerLink.name === 'logout' && isAuth) { | ||
| return ( | ||
| <Grid item key={headerLink.name}> | ||
| <a className={styles.link} href={headerLink.href}> | ||
| {headerLink.label} | ||
| </a> | ||
| </Grid> | ||
| ); | ||
| } else if (headerLink.name === 'logout' && !isAuth) { | ||
| return null; | ||
| } | ||
|
|
||
| if (headerLink.name === 'login' && isAuth) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
This can probably be rewritten to be easier to understand - maybe something like the following, outside of the .map call:
const links = headerLinks;
if (isAuth) {
links.push(logout button config object);
} else {
links.push(login button config object);
}
links.map(link => etc etc| name: 'google', | ||
| label: 'google', | ||
| href: 'http://localhost:5000/auth/google/', | ||
| }, |
There was a problem hiding this comment.
This comment still stands^
| { | ||
| name: 'google', | ||
| label: 'google', | ||
| href: 'http://localhost:5000/auth/google/', |
There was a problem hiding this comment.
we shouldn't hardcode localhost:5000
| "google_id" character varying DEFAULT NULL, | ||
| "google_picture" character varying DEFAULT NULL, | ||
| "password_digest" character varying, |
There was a problem hiding this comment.
we shouldn't edit existing migrations - if you're changing a model, create a new migration.
|
|
||
| export const main = async (app: Express) => { | ||
| await initDB(); | ||
| app.use(session({ secret: 'secret' })); |
|
|
||
| const router = express.Router(); | ||
|
|
||
| router |
There was a problem hiding this comment.
I think in other files we are not chaining multiple routes together - each get request here should be its own statement
| (req, res) => { | ||
| console.log('GOTHERE! '); | ||
| console.log('req.user ', req.user); | ||
| res.redirect('http://localhost:3000/'); |
| done(null, user.id); | ||
| }); | ||
|
|
||
| passport.deserializeUser(async (userId: any, done) => { |
There was a problem hiding this comment.
we know userId will be a number, so we can type it as such here
|
@all-contributors please add @pdotsani for code |
|
I've put up a pull request to add @pdotsani! 🎉 |
46bea20 to
026ea3d
Compare
f60e5cd to
7fe4410
Compare
b3e4641 to
5362e0e
Compare
|
Today's meeting included a good deal of conversation about how Google Auth would limit use cases in countries like China or even certain government agencies. So, we left the conversation leaning very heavily to going back to an email solution. There are some contributors like @timmyichen @vkWeb @AryanJ-NYC from #306 who were part of previous authentication conversations who weren't part of today's conversation, so please see the meeting notes. If Google Auth is off the table, we'd need to at least :
|
|
@QuincyLarson @pdotsani @Zeko369 is my last comment and link to the meeting notes an accurate summary of today's conversation? |
|
Closing since the direction changed to using email-based authentication on #437. |

Update README.md).masterbranch of Chapter.Closes #306
This feature requires new dependencies and a few environment variables to run. You can create these credentials/keys at console.cloud.google.com or ping me on discord.