From 940a8b5fdad9914f55f213beb72d949b9642d160 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:16:23 -0400 Subject: [PATCH 1/8] chore: node ssr rendering --- astro.config.mjs | 9 +++- package-lock.json | 127 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++ 3 files changed, 137 insertions(+), 2 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 2a862b3..3b702db 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -2,11 +2,16 @@ import { defineConfig } from "astro/config"; import mdx from "@astrojs/mdx"; import sitemap from "@astrojs/sitemap"; import tailwind from "@astrojs/tailwind"; - import react from "@astrojs/react"; +import node from "@astrojs/node"; + // https://astro.build/config export default defineConfig({ site: "https://example.com", - integrations: [mdx(), sitemap(), tailwind(), react()] + output: "hybrid", + integrations: [mdx(), sitemap(), tailwind(), react()], + adapter: node({ + mode: "standalone" + }) }); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 2078229..14f0484 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@astrojs/check": "^0.5.3", "@astrojs/mdx": "^2.1.1", + "@astrojs/node": "^8.3.3", "@astrojs/react": "^3.1.0", "@astrojs/rss": "^4.0.5", "@astrojs/sitemap": "^3.0.5", @@ -32,11 +33,13 @@ "react-dom": "^18.2.0", "react-hook-form": "^7.51.3", "react-select": "^5.8.0", + "simple-oauth2": "2.5.2", "tailwindcss": "^3.4.1", "typescript": "^5.3.3" }, "devDependencies": { "@brown-ccv/eslint-config": "^0.3.0", + "@types/simple-oauth2": "^2.5.2", "eslint": "^8.56.0", "eslint-plugin-astro": "^0.31.4", "prettier": "^3.2.5", @@ -186,6 +189,18 @@ "astro": "^4.0.0" } }, + "node_modules/@astrojs/node": { + "version": "8.3.3", + "resolved": "https://registry.npmjs.org/@astrojs/node/-/node-8.3.3.tgz", + "integrity": "sha512-idrKhnnPSi0ABV+PCQsRQqVNwpOvVDF/+fkwcIiE8sr9J8EMvW9g/oyAt8T4X2OBJ8FUzYPL8klfCdG7r0eB5g==", + "dependencies": { + "send": "^0.18.0", + "server-destroy": "^1.0.1" + }, + "peerDependencies": { + "astro": "^4.2.0" + } + }, "node_modules/@astrojs/prism": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@astrojs/prism/-/prism-3.1.0.tgz", @@ -2619,11 +2634,50 @@ "node": ">=10" } }, + "node_modules/@hapi/address": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@hapi/address/-/address-2.1.4.tgz", + "integrity": "sha512-QD1PhQk+s31P1ixsX0H0Suoupp3VMXzIVMSwobR3F3MSUO2YCV0B7xqLcUw/Bh8yuvd3LhpyqLQWTNcRmp6IdQ==", + "deprecated": "Moved to 'npm install @sideway/address'" + }, + "node_modules/@hapi/bourne": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@hapi/bourne/-/bourne-1.3.2.tgz", + "integrity": "sha512-1dVNHT76Uu5N3eJNTYcvxee+jzX4Z9lfciqRRHCU27ihbUcYi+iSc2iml5Ke1LXe1SyJCLA0+14Jh4tXJgOppA==", + "deprecated": "This version has been deprecated and is no longer supported or maintained" + }, "node_modules/@hapi/hoek": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==" }, + "node_modules/@hapi/joi": { + "version": "15.1.1", + "resolved": "https://registry.npmjs.org/@hapi/joi/-/joi-15.1.1.tgz", + "integrity": "sha512-entf8ZMOK8sc+8YfeOlM8pCfg3b5+WZIKBfUaaJT8UsjAAPjartzxIYm3TIbjvA4u+u++KbcXD38k682nVHDAQ==", + "deprecated": "Switch to 'npm install joi'", + "dependencies": { + "@hapi/address": "2.x.x", + "@hapi/bourne": "1.x.x", + "@hapi/hoek": "8.x.x", + "@hapi/topo": "3.x.x" + } + }, + "node_modules/@hapi/joi/node_modules/@hapi/hoek": { + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-8.5.1.tgz", + "integrity": "sha512-yN7kbciD87WzLGc5539Tn0sApjyiGHAJgKvG9W8C7O+6c7qmoQMfVs0W4bX17eqz6C78QJqqFrtgdK5EWf6Qow==", + "deprecated": "This version has been deprecated and is no longer supported or maintained" + }, + "node_modules/@hapi/joi/node_modules/@hapi/topo": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-3.1.6.tgz", + "integrity": "sha512-tAag0jEcjwH+P2quUfipd7liWCNX2F8NvYjQp2wtInsZxnMlypdw0FtAOLxtvvkO+GSRRbmNi8m/5y42PQJYCQ==", + "deprecated": "This version has been deprecated and is no longer supported or maintained", + "dependencies": { + "@hapi/hoek": "^8.3.0" + } + }, "node_modules/@hapi/topo": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", @@ -5947,6 +6001,12 @@ "dev": true, "peer": true }, + "node_modules/@types/simple-oauth2": { + "version": "2.5.8", + "resolved": "https://registry.npmjs.org/@types/simple-oauth2/-/simple-oauth2-2.5.8.tgz", + "integrity": "sha512-Q0g/wUAix1VjP1T0FfO53lZmRElo91sbyGbr/ns0fpWwfU1Op1BbHAtqictipVNMqaney2CyOCLfa3bwAqi37A==", + "dev": true + }, "node_modules/@types/triple-beam": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", @@ -8359,6 +8419,24 @@ "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==" }, + "node_modules/boom": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/boom/-/boom-7.3.0.tgz", + "integrity": "sha512-Swpoyi2t5+GhOEGw8rEsKvTxFLIDiiKoUc2gsoV6Lyr43LHBIzch3k2MvYUs8RTROrIkVJ3Al0TkaOGjnb+B6A==", + "deprecated": "This module has moved and is now available at @hapi/boom. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.", + "dependencies": { + "hoek": "6.x.x" + } + }, + "node_modules/bourne": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/bourne/-/bourne-1.3.3.tgz", + "integrity": "sha512-6K4uuAlRGcorC6aV2Y1rypeQ17grx4XKyVyG6NA963PwRfxyievy0CDXtiSBPKvIc7OTpcJRT86X3mU7j5Zp9A==", + "deprecated": "This module has moved and is now available at @hapi/bourne. Please update your dependencies as this version is no longer maintained and may contain bugs and security issues.", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/boxen": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/boxen/-/boxen-7.1.1.tgz", @@ -11557,6 +11635,12 @@ "@babel/runtime": "^7.7.6" } }, + "node_modules/hoek": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-6.1.3.tgz", + "integrity": "sha512-YXXAAhmF9zpQbC7LEcREFtXfGq5K1fmd+4PHkBq8NUqmzW3G+Dq10bI/i0KucLRwss3YYFQ0fSfoxBZYiGUqtQ==", + "deprecated": "This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues." + }, "node_modules/hoist-non-react-statics": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", @@ -16482,6 +16566,11 @@ "node": ">= 0.8.0" } }, + "node_modules/server-destroy": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/server-destroy/-/server-destroy-1.0.1.tgz", + "integrity": "sha512-rb+9B5YBIEzYcD6x2VKidaa+cqYBJQKnU4oe4E3ANwRRN56yk/ua1YCJT1n21NTS8w6CcOclAKNP3PhdCXKYtQ==" + }, "node_modules/set-function-length": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", @@ -16643,6 +16732,33 @@ "url": "https://github.com/steveukx/git-js?sponsor=1" } }, + "node_modules/simple-oauth2": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/simple-oauth2/-/simple-oauth2-2.5.2.tgz", + "integrity": "sha512-8qjf+nHRdSUllFjjfpnonrU1oF/HNVbDle5HIbvXRYiy38C7KUvYe6w0ZZ//g4AFB6VNWuiZ80HmnycR8ZFDyQ==", + "deprecated": "simple-oauth2 v2 is no longer supported. Please upgrade to v3 for further support", + "dependencies": { + "@hapi/joi": "^15.1.1", + "date-fns": "^2.2.1", + "debug": "^4.1.1", + "wreck": "^14.0.2" + } + }, + "node_modules/simple-oauth2/node_modules/date-fns": { + "version": "2.30.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz", + "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==", + "dependencies": { + "@babel/runtime": "^7.21.0" + }, + "engines": { + "node": ">=0.11" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/date-fns" + } + }, "node_modules/simple-swizzle": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", @@ -18818,6 +18934,17 @@ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" }, + "node_modules/wreck": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/wreck/-/wreck-14.2.0.tgz", + "integrity": "sha512-NFFft3SMgqrJbXEVfYifh+QDWFxni+98/I7ut7rLbz3F0XOypluHsdo3mdEYssGSirMobM3fGlqhyikbWKDn2Q==", + "deprecated": "This module has moved and is now available at @hapi/wreck. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.", + "dependencies": { + "boom": "7.x.x", + "bourne": "1.x.x", + "hoek": "6.x.x" + } + }, "node_modules/xml-utils": { "version": "1.10.1", "resolved": "https://registry.npmjs.org/xml-utils/-/xml-utils-1.10.1.tgz", diff --git a/package.json b/package.json index b201a3b..5caad65 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "dependencies": { "@astrojs/check": "^0.5.3", "@astrojs/mdx": "^2.1.1", + "@astrojs/node": "^8.3.3", "@astrojs/react": "^3.1.0", "@astrojs/rss": "^4.0.5", "@astrojs/sitemap": "^3.0.5", @@ -36,11 +37,13 @@ "react-dom": "^18.2.0", "react-hook-form": "^7.51.3", "react-select": "^5.8.0", + "simple-oauth2": "2.5.2", "tailwindcss": "^3.4.1", "typescript": "^5.3.3" }, "devDependencies": { "@brown-ccv/eslint-config": "^0.3.0", + "@types/simple-oauth2": "^2.5.2", "eslint": "^8.56.0", "eslint-plugin-astro": "^0.31.4", "prettier": "^3.2.5", From e3f4574e4bfcda8921e613cb4822829d1bc3da19 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:16:42 -0400 Subject: [PATCH 2/8] feat: api endpoints for auth --- api/_lib/oauth2.ts | 30 ++++++++++++++++++++++++++++++ src/pages/api/auth.astro | 9 +++++++++ src/pages/api/auth.ts | 17 +++++++++++++++++ src/pages/api/callback.astro | 8 ++++++++ src/pages/api/callback.ts | 25 +++++++++++++++++++++++++ 5 files changed, 89 insertions(+) create mode 100644 api/_lib/oauth2.ts create mode 100644 src/pages/api/auth.astro create mode 100644 src/pages/api/auth.ts create mode 100644 src/pages/api/callback.astro create mode 100644 src/pages/api/callback.ts diff --git a/api/_lib/oauth2.ts b/api/_lib/oauth2.ts new file mode 100644 index 0000000..c59a197 --- /dev/null +++ b/api/_lib/oauth2.ts @@ -0,0 +1,30 @@ +import * as simpleOauthModule from "simple-oauth2" + +export const create = () => + simpleOauthModule.create({ + client: { + id: process.env.OAUTH_CLIENT_ID || "", + secret: process.env.OAUTH_CLIENT_SECRET || "", + }, + auth: { + tokenHost: `https://github.com`, + tokenPath: `/login/oauth/access_token`, + authorizePath: `/login/oauth/authorize`, + }, + }) + +export const renderBody = (status: string, content: object) => ` + +` diff --git a/src/pages/api/auth.astro b/src/pages/api/auth.astro new file mode 100644 index 0000000..a6175a6 --- /dev/null +++ b/src/pages/api/auth.astro @@ -0,0 +1,9 @@ +--- +import Layout from "../../layouts/Layout.astro" +import { GET } from "./auth" + +const auth = await GET() +--- + + + diff --git a/src/pages/api/auth.ts b/src/pages/api/auth.ts new file mode 100644 index 0000000..e1ad1cb --- /dev/null +++ b/src/pages/api/auth.ts @@ -0,0 +1,17 @@ +import crypto from "crypto" +import { create } from "../../../api/_lib/oauth2.ts" + +export const prerender = false + +export const GET = () => { + const randomString = () => crypto.randomBytes(4).toString(`hex`) + const host = "https://mmp-site-b1c9b.web.app" + const oauth2 = create() + + const url = oauth2.authorizationCode.authorizeURL({ + redirect_uri: `${host}/api/callback`, + scope: `repo,user`, + state: randomString(), + }) + return Response.redirect(url, 301) +} diff --git a/src/pages/api/callback.astro b/src/pages/api/callback.astro new file mode 100644 index 0000000..8b6f0d2 --- /dev/null +++ b/src/pages/api/callback.astro @@ -0,0 +1,8 @@ +--- +import Layout from "../../layouts/Layout.astro" +import { GetCallback } from "./callback" + +const callback = GetCallback(Astro.request) +--- + + diff --git a/src/pages/api/callback.ts b/src/pages/api/callback.ts new file mode 100644 index 0000000..5213ac3 --- /dev/null +++ b/src/pages/api/callback.ts @@ -0,0 +1,25 @@ +import { create, renderBody } from "../../../api/_lib/oauth2.ts" + +export const GetCallback = async (req: Request) => { + const params = new URLSearchParams(req.url) + const code = params.get("code") || "" + const host = "https://mmp-site-b1c9b.web.app" + const oauth2 = create() + + try { + const accessToken = await oauth2.authorizationCode.getToken({ + code, + redirect_uri: `${host}/api/callback`, + }) + const { token } = oauth2.accessToken.create(accessToken) + return Response.redirect( + renderBody("success", { + token: token.access_token, + provider: "github", + }), + 200 + ) + } catch (e: any) { + return Response.redirect(renderBody("error", e.message), 200) + } +} From 43f81e247cd2b00a10db7f4a8ad72456683bc0f3 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:16:50 -0400 Subject: [PATCH 3/8] chore: base_url live site --- public/admin/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/admin/config.yml b/public/admin/config.yml index cd727e3..d604cfe 100644 --- a/public/admin/config.yml +++ b/public/admin/config.yml @@ -3,7 +3,8 @@ local_backend: true backend: name: github repo: brown-ccv/mmp - base_url: / + base_url: https://mmp-site-b1c9b.web.app/ + auth_endpoint: api/auth media_folder: public/images media_library: max_file_size: 734003200 From 77ca3645d6dde320fc6b97a4e26d0b6e2ba17138 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:42:08 -0400 Subject: [PATCH 4/8] chore: pass host from astro --- src/pages/api/auth.astro | 5 ++--- src/pages/api/auth.ts | 3 +-- src/pages/api/callback.astro | 2 +- src/pages/api/callback.ts | 5 +++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/pages/api/auth.astro b/src/pages/api/auth.astro index a6175a6..63ead9d 100644 --- a/src/pages/api/auth.astro +++ b/src/pages/api/auth.astro @@ -2,8 +2,7 @@ import Layout from "../../layouts/Layout.astro" import { GET } from "./auth" -const auth = await GET() +const auth = await GET(Astro.url.origin) --- - - + diff --git a/src/pages/api/auth.ts b/src/pages/api/auth.ts index e1ad1cb..c124505 100644 --- a/src/pages/api/auth.ts +++ b/src/pages/api/auth.ts @@ -3,9 +3,8 @@ import { create } from "../../../api/_lib/oauth2.ts" export const prerender = false -export const GET = () => { +export const GET = (host: string) => { const randomString = () => crypto.randomBytes(4).toString(`hex`) - const host = "https://mmp-site-b1c9b.web.app" const oauth2 = create() const url = oauth2.authorizationCode.authorizeURL({ diff --git a/src/pages/api/callback.astro b/src/pages/api/callback.astro index 8b6f0d2..bfaf901 100644 --- a/src/pages/api/callback.astro +++ b/src/pages/api/callback.astro @@ -2,7 +2,7 @@ import Layout from "../../layouts/Layout.astro" import { GetCallback } from "./callback" -const callback = GetCallback(Astro.request) +const callback = GetCallback(Astro.request, Astro.url.origin) --- diff --git a/src/pages/api/callback.ts b/src/pages/api/callback.ts index 5213ac3..bc986e1 100644 --- a/src/pages/api/callback.ts +++ b/src/pages/api/callback.ts @@ -1,9 +1,10 @@ import { create, renderBody } from "../../../api/_lib/oauth2.ts" -export const GetCallback = async (req: Request) => { +export const prerender = false + +export const GetCallback = async (req: Request, host: string) => { const params = new URLSearchParams(req.url) const code = params.get("code") || "" - const host = "https://mmp-site-b1c9b.web.app" const oauth2 = create() try { From aaf2feb45fcb2ea1f9924163118ee011bc5d16ef Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Tue, 20 Aug 2024 13:52:29 -0400 Subject: [PATCH 5/8] fix: return response --- src/pages/api/callback.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/api/callback.ts b/src/pages/api/callback.ts index bc986e1..01a9275 100644 --- a/src/pages/api/callback.ts +++ b/src/pages/api/callback.ts @@ -13,14 +13,14 @@ export const GetCallback = async (req: Request, host: string) => { redirect_uri: `${host}/api/callback`, }) const { token } = oauth2.accessToken.create(accessToken) - return Response.redirect( + return new Response( renderBody("success", { token: token.access_token, provider: "github", }), - 200 + { status: 200 } ) } catch (e: any) { - return Response.redirect(renderBody("error", e.message), 200) + return new Response(renderBody("error", e.message), { status: 200 }) } } From ef8e69bb9efa120b6c60dfd7f5456bf0d5b61100 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:43:47 -0400 Subject: [PATCH 6/8] chore: move api to src --- public/admin/config.yml | 2 -- {api => src/api}/_lib/oauth2.ts | 0 src/pages/api/auth.astro | 11 +++++++++++ src/pages/api/auth.ts | 2 +- src/pages/api/callback.ts | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) rename {api => src/api}/_lib/oauth2.ts (100%) diff --git a/public/admin/config.yml b/public/admin/config.yml index d604cfe..2b46828 100644 --- a/public/admin/config.yml +++ b/public/admin/config.yml @@ -1,5 +1,3 @@ -local_backend: true - backend: name: github repo: brown-ccv/mmp diff --git a/api/_lib/oauth2.ts b/src/api/_lib/oauth2.ts similarity index 100% rename from api/_lib/oauth2.ts rename to src/api/_lib/oauth2.ts diff --git a/src/pages/api/auth.astro b/src/pages/api/auth.astro index 63ead9d..fa1d357 100644 --- a/src/pages/api/auth.astro +++ b/src/pages/api/auth.astro @@ -3,6 +3,17 @@ import Layout from "../../layouts/Layout.astro" import { GET } from "./auth" const auth = await GET(Astro.url.origin) + +const receiveMessage = (message) => { + window.opener.postMessage( + "authorization:github:${status}:${JSON.stringify(content)}", + message.origin + ) + window.removeEventListener("message", receiveMessage, false) +} +window.addEventListener("message", receiveMessage, false) + +window.opener.postMessage("authorizing:github", "*") --- diff --git a/src/pages/api/auth.ts b/src/pages/api/auth.ts index c124505..ec459fc 100644 --- a/src/pages/api/auth.ts +++ b/src/pages/api/auth.ts @@ -1,5 +1,5 @@ import crypto from "crypto" -import { create } from "../../../api/_lib/oauth2.ts" +import { create } from "../../api/_lib/oauth2.ts" export const prerender = false diff --git a/src/pages/api/callback.ts b/src/pages/api/callback.ts index 01a9275..ced7e23 100644 --- a/src/pages/api/callback.ts +++ b/src/pages/api/callback.ts @@ -1,4 +1,4 @@ -import { create, renderBody } from "../../../api/_lib/oauth2.ts" +import { create, renderBody } from "../../api/_lib/oauth2.ts" export const prerender = false From ae1803808d4e01ed3d2ffd93976b6a2d58859ec2 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:50:23 -0400 Subject: [PATCH 7/8] fix: message type --- src/pages/api/auth.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/api/auth.astro b/src/pages/api/auth.astro index fa1d357..44add1c 100644 --- a/src/pages/api/auth.astro +++ b/src/pages/api/auth.astro @@ -4,7 +4,7 @@ import { GET } from "./auth" const auth = await GET(Astro.url.origin) -const receiveMessage = (message) => { +const receiveMessage = (message: MessageEvent) => { window.opener.postMessage( "authorization:github:${status}:${JSON.stringify(content)}", message.origin From cc272aaf0a3c21e1912ed5904d6746f667c48a68 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Mon, 26 Aug 2024 13:54:45 -0400 Subject: [PATCH 8/8] fix: script tags for accessing window on client for astro --- src/pages/api/auth.astro | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/pages/api/auth.astro b/src/pages/api/auth.astro index 44add1c..ba9f176 100644 --- a/src/pages/api/auth.astro +++ b/src/pages/api/auth.astro @@ -3,17 +3,19 @@ import Layout from "../../layouts/Layout.astro" import { GET } from "./auth" const auth = await GET(Astro.url.origin) - -const receiveMessage = (message: MessageEvent) => { - window.opener.postMessage( - "authorization:github:${status}:${JSON.stringify(content)}", - message.origin - ) - window.removeEventListener("message", receiveMessage, false) -} -window.addEventListener("message", receiveMessage, false) - -window.opener.postMessage("authorizing:github", "*") --- + +