@caiquecamargo/vite-plugin-netlify-cms 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caiquecamargo/vite-plugin-netlify-cms",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"author": "Caique de Camargo",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"repository": {
|
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
"module": "./dist/index.js",
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
24
|
"files": [
|
|
25
|
-
"dist"
|
|
25
|
+
"dist",
|
|
26
|
+
"src/oauth/astro-callback.ts",
|
|
27
|
+
"src/oauth/astro-login.ts"
|
|
26
28
|
],
|
|
27
29
|
"peerDependencies": {
|
|
28
30
|
"vite": "^7.0.0"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { clientId, clientSecret, tokenUrl } from './config';
|
|
2
|
+
|
|
3
|
+
export const prerender = false;
|
|
4
|
+
|
|
5
|
+
export async function GET({ url, redirect }: any) {
|
|
6
|
+
const code = url.searchParams.get('code');
|
|
7
|
+
|
|
8
|
+
if (!code) {
|
|
9
|
+
return new Response('<html><body><h1>Error</h1><p>No code provided</p></body></html>', {
|
|
10
|
+
status: 400,
|
|
11
|
+
headers: { 'Content-Type': 'text/html' },
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const data = {
|
|
16
|
+
code,
|
|
17
|
+
client_id: clientId,
|
|
18
|
+
client_secret: clientSecret,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(tokenUrl, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: {
|
|
25
|
+
'Accept': 'application/json',
|
|
26
|
+
'Content-Type': 'application/json',
|
|
27
|
+
},
|
|
28
|
+
body: JSON.stringify(data),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const body = await response.json();
|
|
36
|
+
|
|
37
|
+
const content = {
|
|
38
|
+
token: body.access_token,
|
|
39
|
+
provider: 'github',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Return HTML with postMessage script to communicate with CMS
|
|
43
|
+
const script = `
|
|
44
|
+
<script>
|
|
45
|
+
const receiveMessage = (message) => {
|
|
46
|
+
window.opener.postMessage(
|
|
47
|
+
'authorization:${content.provider}:success:${JSON.stringify(content)}',
|
|
48
|
+
message.origin
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
window.removeEventListener("message", receiveMessage, false);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
window.addEventListener("message", receiveMessage, false);
|
|
55
|
+
|
|
56
|
+
window.opener.postMessage("authorizing:${content.provider}", "*");
|
|
57
|
+
</script>
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
return new Response(script, {
|
|
61
|
+
headers: { 'Content-Type': 'text/html' },
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
console.error('OAuth callback error:', err);
|
|
66
|
+
return redirect('/?error=oauth_failed');
|
|
67
|
+
}
|
|
68
|
+
}
|