-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
chore(providers): rewrite github provider in typescript #4908
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
// If user has email hidden, get their primary email from the GitHub API | ||
if (!profile.email) { | ||
const emails: GithubEmail[] = await ( | ||
await fetch("https://api.github.com/user/emails", { | ||
headers: { Authorization: `token ${tokens.access_token}` }, | ||
}) | ||
).json() | ||
|
||
if (emails?.length > 0) { | ||
// Get primary email | ||
profile.email = emails.find((email) => email.primary)?.email | ||
// And if for some reason it doesn't exist, just use the first | ||
if (!profile.email) profile.email = emails[0].email | ||
} | ||
} |
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'm not sure if this is still needed. But probably somebody added it for a reason.
|
||
// If user has email hidden, get their primary email from the GitHub API | ||
if (!profile.email) { | ||
const emails: GithubEmail[] = await ( |
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've added to the types to the email request too.
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.
Awesome, thanks!
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.
Linting failed, other than that, looks good!
Co-authored-by: Balázs Orbán <info@balazsorban.com>
url: "https://api.github.com/user", | ||
async request({ client, tokens }) { | ||
// Get base profile | ||
const profile = await client.userinfo(tokens.access_token!) |
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.
https://github.com/nextauthjs/next-auth/runs/7305230206?check_suite_focus=true#step:7:22
This throws as well. I believe it should always be string
though, so maybe a // @ts-expect-error
is forgivable here. If not, we can change it to throw an error in the future.
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've added the same behavior of https://github.com/nextauthjs/next-auth/blob/main/packages/next-auth/src/providers/facebook.ts
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.
Thanks!
I rewrote the provider from js to ts and added the profile types.
I've tested it with two accounts, but please test it further as it's a critical provider.
☕️ Reasoning
Embrace typescript
🧢 Checklist
🎫 Affected issues
Please scout and link issues that might be solved by this PR.
Fixes: INSERT_ISSUE_LINK_HERE
📌 Resources