-
Notifications
You must be signed in to change notification settings - Fork 29
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
chore: rate limit modal and auto login #22
Changes from all commits
db89905
2f026db
473078e
30957fc
00f7a15
301729a
e5c6669
5b66bd4
065c84e
dac1eab
9c26568
6465f5c
68a77c0
f676a93
365aafa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
SUPABASE_URL= | ||
SUPABASE_ANON_KEY= | ||
SUPABASE_ANON_KEY= |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,15 +2,13 @@ import { Octokit } from "@octokit/rest"; | |||||
import { GitHubUser, GitHubUserResponse } from "../github-types"; | ||||||
import { OAuthToken } from "./get-github-access-token"; | ||||||
import { getLocalStore } from "./get-local-store"; | ||||||
import { handleRateLimit } from "../fetch-github/fetch-issues-preview"; | ||||||
import { RequestError } from "@octokit/request-error"; | ||||||
declare const SUPABASE_STORAGE_KEY: string; // @DEV: passed in at build time check build/esbuild-build.ts | ||||||
|
||||||
export async function getGitHubUser(): Promise<GitHubUser | null> { | ||||||
const activeSessionToken = await getSessionToken(); | ||||||
if (activeSessionToken) { | ||||||
return getNewGitHubUser(activeSessionToken); | ||||||
} else { | ||||||
return null; | ||||||
} | ||||||
return getNewGitHubUser(activeSessionToken); | ||||||
} | ||||||
|
||||||
async function getSessionToken(): Promise<string | null> { | ||||||
|
@@ -30,13 +28,22 @@ async function getNewSessionToken(): Promise<string | null> { | |||||
const params = new URLSearchParams(hash.substr(1)); // remove the '#' and parse | ||||||
const providerToken = params.get("provider_token"); | ||||||
if (!providerToken) { | ||||||
return null; | ||||||
const error = params.get("error_description"); | ||||||
// supabase auth provider has failed for some reason | ||||||
console.error(`GitHub login provider: ${error}`); | ||||||
} | ||||||
return providerToken; | ||||||
return providerToken || null; | ||||||
} | ||||||
|
||||||
async function getNewGitHubUser(providerToken: string): Promise<GitHubUser> { | ||||||
async function getNewGitHubUser(providerToken: string | null): Promise<GitHubUser | null> { | ||||||
const octokit = new Octokit({ auth: providerToken }); | ||||||
const response = (await octokit.request("GET /user")) as GitHubUserResponse; | ||||||
return response.data; | ||||||
try { | ||||||
const response = (await octokit.request("GET /user")) as GitHubUserResponse; | ||||||
0x4007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return response.data; | ||||||
} catch (error) { | ||||||
if (error instanceof RequestError && error.status === 403) { | ||||||
await handleRateLimit(providerToken ? octokit : undefined, error); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is this more concise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although if there is a If we make this more concise we litter the rate limit function I guess |
||||||
} | ||||||
} | ||||||
return null; | ||||||
} |
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.
Does this take the UTC into account when displayed?
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.
It uses local time. This is relevant for the user, and in my testing, it is accurate.
Just realized, this pull needs to be rebased/reopened. Pretty sure this is my code from a long time ago that's already in production.
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.
The code is similar I guess but this pr is up to date with development if that's where prod is running from