Skip to content

Commit

Permalink
feat: fixed githubUserId and added providerToken checker
Browse files Browse the repository at this point in the history
  • Loading branch information
koya0 committed Oct 16, 2024
1 parent 2c7a6a7 commit 4667f12
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions functions/validators.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import { CustomRequest } from "./types";
import { OAuthToken } from "../src/home/getters/get-github-access-token";
import { Octokit } from "@octokit/rest";

export async function validatePOST(url: URL, request: CustomRequest): Promise<boolean> {
try {
const jsonData: unknown = await request.json();

const authToken = jsonData as OAuthToken;

const githubUserId = authToken?.user?.id;
const providerToken = authToken?.provider_token;

if (providerToken) {
const octokit = new Octokit({ auth: providerToken });

try {
await octokit.request("GET /user");

const githubUserId = authToken?.user?.user_metadata?.provider_id;

const key = url.searchParams.get("key");

const key = url.searchParams.get("key");
if (githubUserId && githubUserId === key) {
return true;
}

if (githubUserId && githubUserId == key) {
return true;
return false;
} catch (error) {
console.error("User is not logged in");
return false;
}
}
return false;
} catch (error) {
Expand Down

0 comments on commit 4667f12

Please sign in to comment.