-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add restricted access on github auth #353
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job. I left a couple comments
import { signIn } from 'next-auth/react'; | ||
import * as React from 'react'; | ||
import { signIn } from "next-auth/react"; | ||
import * as React from "react"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: redundant import
setIsLoading(true); | ||
await signIn("github", { callbackUrl }); | ||
} catch (error) { | ||
console.error(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we maybe do toast in addition to/instead of console.log?
frontend/lib/server-utils.ts
Outdated
const filePath = path.join(process.cwd(), "allowed-emails.json"); | ||
|
||
if (!fs.existsSync(filePath)) { | ||
console.log("file not found :("); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: do we really need this? If this is not debug log I suggest we either remove it or make it more informative
frontend/lib/server-utils.ts
Outdated
const jsonData = JSON.parse(fileContent) as { emails: string[] }; | ||
return jsonData.emails; | ||
} catch (e) { | ||
console.error(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's make this a little more informative, e.g. Failed to read allowed-emails.json ${e}
frontend/lib/server-utils.ts
Outdated
const jsonData = JSON.parse(fileContent) as { emails: string[] }; | ||
return jsonData.emails; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this may throw TS errors, I think it will silently return undefined
for valid JSON files with invalid format. Please handle, by at least returning jsonData.emails ?? []
or better throw an error if jsonData.emails === undefined
frontend/lib/server-utils.ts
Outdated
const jsonData = JSON.parse(fileContent) as { emails: string[] }; | ||
return jsonData.emails; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though this may throw TS errors, I think it will silently return undefined
for valid JSON files with invalid format. Please handle, by at least returning jsonData.emails ?? []
or better throw an error if jsonData.emails === undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- we might also want to validate every email, but that might be overkill – up to you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think email validation might be too much
@dinmukhamedm yes agree with all comments, should have fixed them before, should be good now, for the emails part I agree we need fallback or error throw, I added error throw though if needed we can make fallback for empty list, meaning no user will be able to pass github signin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Changes requested. Reviewed everything up to 855bacc in 1 minute and 57 seconds
More details
- Looked at
511
lines of code in6
files - Skipped
0
files when reviewing. - Skipped posting
1
drafted comments based on config settings.
1. frontend/components/sign-in/email-signin.tsx:43
- Draft comment:
ThehandleEnter
prop is not defined in the Button component's props. Consider removing it or implementing it in the Button component. - Reason this comment was not posted:
Comment was on unchanged code.
Workflow ID: wflow_KfkpCB94KpD8oF5l
Want Ellipsis to fix these issues? Tag @ellipsis-dev
in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
frontend/lib/server-utils.ts
Outdated
return false; | ||
} | ||
|
||
const fileContent = fs.readFileSync(filePath, "utf-8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using fs.promises.readFile
instead of fs.readFileSync
to avoid blocking the event loop in an async function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olzhik11 please have a look if that makes sense
frontend/lib/server-utils.ts
Outdated
|
||
const fileContent = fs.readFileSync(filePath, "utf-8"); | ||
|
||
const jsonData = JSON.parse(fileContent) as { emails?: string[] }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a try-catch block around JSON.parse to handle potential JSON parsing errors gracefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@olzhik11 please address
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dinmukhamedm for this one then we won't be able to throw error if file doesn't match structure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dinmukhamedm I added fallback instead, and throw on file parsing error
Added access control on
github
auth through json fileImportant
Added restricted access for GitHub authentication using a JSON file to control allowed emails.
signIn
callback inauth.ts
to restrict GitHub access based on emails fromallowed-emails.json
.getEmailsConfig
inserver-utils.ts
to read allowed emails from JSON.GitHubSignInButton
ingithub-signin.tsx
to handle sign-in errors with toast notifications.EmailSignInButton
inemail-signin.tsx
by removing unused props.GITHUB_AUTH
infeatures.ts
to ensure GitHub credentials are set.This description was created by for 855bacc. It will automatically update as commits are pushed.