This repository has been archived by the owner on Dec 19, 2024. It is now read-only.
-
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.
test: OliverSpeir/astro-decap-starter-ssr/
- Loading branch information
Showing
11 changed files
with
101 additions
and
119 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="robots" content="noindex" /> | ||
<link href="/admin/config.yml" type="text/yaml" rel="cms-config-url" /> | ||
<title>Content Manager</title> | ||
</head> | ||
<body> | ||
<!-- Dashboard script--> | ||
<script src="https://unpkg.com/decap-cms@^3.1.0-beta.2/dist/decap-cms.js"></script> | ||
<!-- CSS in preview panel --> | ||
<script> | ||
// @ts-expect-error CMS is defined globally | ||
// eslint-disable-next-line | ||
CMS.registerPreviewStyle("/global.css") | ||
</script> | ||
|
||
<!-- Only showing body in preview panel --> | ||
<script src="@utils/preview.js"></script> | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
export const clientId = process.env.OAUTH_GITHUB_CLIENT_ID || import.meta.env.OAUTH_GITHUB_CLIENT_ID | ||
export const clientSecret = | ||
process.env.OAUTH_GITHUB_CLIENT_SECRET || import.meta.env.OAUTH_GITHUB_CLIENT_SECRET | ||
|
||
export const authUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&scope=repo,user` | ||
export const tokenUrl = "https://github.com/login/oauth/access_token" |
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,61 @@ | ||
export const prerender = "false" | ||
import type { APIRoute } from "astro" | ||
import { clientId, clientSecret, tokenUrl } from "./_config" | ||
|
||
export const GET: APIRoute = async ({ url, redirect }) => { | ||
const data = { | ||
code: url.searchParams.get("code"), | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
} | ||
|
||
let script | ||
|
||
try { | ||
const response = await fetch(tokenUrl, { | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(data), | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`) | ||
} | ||
|
||
const body = await response.json() | ||
|
||
const content = { | ||
token: body.access_token, | ||
provider: "github", | ||
} | ||
|
||
// This is what talks to the DecapCMS page. | ||
// Using window.postMessage we give it the token details in a format it's expecting | ||
script = ` | ||
<script> | ||
const receiveMessage = (message) => { | ||
window.opener.postMessage( | ||
'authorization:${content.provider}:success:${JSON.stringify(content)}', | ||
message.origin | ||
); | ||
window.removeEventListener("message", receiveMessage, false); | ||
} | ||
window.addEventListener("message", receiveMessage, false); | ||
window.opener.postMessage("authorizing:${content.provider}", "*"); | ||
</script> | ||
` | ||
|
||
return new Response(script, { | ||
headers: { "Content-Type": "text/html" }, | ||
}) | ||
} catch (err) { | ||
// If we hit an error we'll handle that here | ||
console.log(err) | ||
return redirect("/?error=😡") | ||
} | ||
} |
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,7 @@ | ||
export const prerender = "false" | ||
import type { APIRoute } from "astro" | ||
import { authUrl } from "./_config" | ||
|
||
export const GET: APIRoute = ({ redirect }) => { | ||
return redirect(authUrl) | ||
} |