-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
2,339 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ESA_APP_CLIENT_ID = "xxxxxxxxxxxxxxxxxx" | ||
ESA_APP_CLIENT_SECRET = "xxxxxxxxxxxxxxxxxx" | ||
ESA_APP_REDIRECT_URI = "xxxxxxxxxxxxxxxxxx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
VITE_ESA_APP_CLIENT_ID=xxxxxxxxxxxxxxxxxx | ||
VITE_ESA_APP_REDIRECT_URI=xxxxxxxxxxxxxxxxxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
vite.config.mts | ||
src/vite-env.d.ts | ||
functions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,8 @@ dist-ssr | |
*.sw? | ||
*.env | ||
*.env.local | ||
!.env.example | ||
!.env.example | ||
|
||
src/lib/services/esa.gen.ts | ||
.wrangler/ | ||
.dev.vars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export type Env = { | ||
ESA_APP_CLIENT_ID: string; | ||
ESA_APP_CLIENT_SECRET: string; | ||
ESA_APP_REDIRECT_URI: string; | ||
}; | ||
|
||
export function getEnv<T extends keyof Env>(env: Partial<Env>, key: T): Env[T] { | ||
const value = env[key]; | ||
if (value == null) { | ||
throw new Error(`Environment variable ${key} is not set`); | ||
} | ||
|
||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { PagesFunction } from "@cloudflare/workers-types"; | ||
import { string, object } from "yup"; | ||
import { Env } from "../__lib/consts.js"; | ||
|
||
export const onRequestOptions: PagesFunction<Env> = async ({ env }) => { | ||
return new Response(null, { | ||
status: 204, | ||
headers: { | ||
"Access-Control-Allow-Origin": new URL(env.ESA_APP_REDIRECT_URI).origin, | ||
"Access-Control-Allow-Headers": "*", | ||
"Access-Control-Allow-Methods": "GET, OPTIONS", | ||
"Access-Control-Max-Age": "86400", | ||
}, | ||
}); | ||
}; | ||
|
||
export const onRequest: PagesFunction<Env> = async ({ request, env }) => { | ||
if (request.method !== "POST") { | ||
return new Response("Method not allowed.", { status: 405 }); | ||
} | ||
|
||
const requestAccessTokenSchema = object().shape({ | ||
code: string(), | ||
}); | ||
|
||
let code: string; | ||
try { | ||
code = (await requestAccessTokenSchema.validate(await request.json())).code; | ||
} catch (err) { | ||
return new Response(err, { status: 400 }); | ||
} | ||
|
||
const res = await fetch("https://api.esa.io/oauth/token", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
client_id: env.ESA_APP_CLIENT_ID, | ||
client_secret: env.ESA_APP_CLIENT_SECRET, | ||
code: code, | ||
grant_type: "authorization_code", | ||
redirect_uri: env.ESA_APP_REDIRECT_URI, | ||
}), | ||
}); | ||
|
||
if (!res.ok) { | ||
return new Response("Failed to request access token!", { | ||
status: 500, | ||
}); | ||
} | ||
|
||
return new Response(await res.text(), { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"lib": [ | ||
"esnext" | ||
], | ||
"types": [ | ||
"@cloudflare/workers-types" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
|
||
export const useEsa = () => { | ||
const getAchievement = async (access_token: string, team_name: string) => { | ||
console.log(access_token); | ||
console.log(team_name); | ||
const data = await fetch(`https://api.esa.io/v1/teams/${team_name}/members`, { | ||
method: "GET", | ||
mode: "cors", | ||
headers: { | ||
Authorization: `Bearer ${access_token}`, | ||
"Content-Type": "application/json", | ||
Accept: "application/json", | ||
}, | ||
}); | ||
return await data.json(); | ||
} | ||
return { getAchievement }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import styled from "styled-components"; | ||
|
||
export const Center = styled.div` | ||
height: 100%; | ||
width: 100%; | ||
display: grid; | ||
place-items: center; | ||
place-content: center; | ||
`; |
Oops, something went wrong.