Skip to content

Commit 731eaee

Browse files
committed
cleanup and add dark mode css
1 parent f65a205 commit 731eaee

File tree

5 files changed

+897
-26
lines changed

5 files changed

+897
-26
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ The config file included here is a starter file only; you need to set this up fo
2929
### 4. Profit!
3030

3131
Publish your site and let Cloudflare build it. Go to `/admin/` on your site, and you should see a Login with Github button, which should authenticate you to Github and launch the CMS.
32+
33+
## Credits
34+
35+
I've included a dark-mode CSS file from [Nats-ji/netlify-cms-dark-mode](https://github.com/Nats-ji/netlify-cms-dark-mode).

functions/api/auth.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ export async function onRequest(context) {
88
data, // arbitrary space for passing data between middlewares
99
} = context;
1010

11-
const client_id = env.GITHUB_CLIENT_ID
11+
const client_id = env.GITHUB_CLIENT_ID;
1212

1313
try {
14-
const url = new URL(request.url)
15-
const redirectUrl = new URL('https://github.com/login/oauth/authorize')
16-
redirectUrl.searchParams.set('client_id', client_id)
17-
redirectUrl.searchParams.set('redirect_uri', url.origin + '/api/callback')
18-
redirectUrl.searchParams.set('scope', 'repo user')
14+
const url = new URL(request.url);
15+
const redirectUrl = new URL('https://github.com/login/oauth/authorize');
16+
redirectUrl.searchParams.set('client_id', client_id);
17+
redirectUrl.searchParams.set('redirect_uri', url.origin + '/api/callback');
18+
redirectUrl.searchParams.set('scope', 'repo user');
1919
redirectUrl.searchParams.set(
2020
'state',
2121
crypto.getRandomValues(new Uint8Array(12)).join(''),
22-
)
23-
return Response.redirect(redirectUrl.href, 301)
22+
);
23+
return Response.redirect(redirectUrl.href, 301);
2424

2525
} catch (error) {
26-
console.error(error)
26+
console.error(error);
2727
return new Response(error.message, {
2828
status: 500,
29-
})
29+
});
3030
}
3131
}

functions/api/callback.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ function renderBody(status, content) {
1111
window.addEventListener("message", receiveMessage, false);
1212
window.opener.postMessage("authorizing:github", "*");
1313
</script>
14-
`
15-
const blob = new Blob([html])
16-
return blob
14+
`;
15+
const blob = new Blob([html]);
16+
return blob;
1717
}
1818

1919
export async function onRequest(context) {
@@ -26,12 +26,12 @@ export async function onRequest(context) {
2626
data, // arbitrary space for passing data between middlewares
2727
} = context;
2828

29-
const client_id = env.GITHUB_CLIENT_ID
30-
const client_secret = env.GITHUB_CLIENT_SECRET
29+
const client_id = env.GITHUB_CLIENT_ID;
30+
const client_secret = env.GITHUB_CLIENT_SECRET;
3131

3232
try {
33-
const url = new URL(request.url)
34-
const code = url.searchParams.get('code')
33+
const url = new URL(request.url);
34+
const code = url.searchParams.get('code');
3535
const response = await fetch(
3636
'https://github.com/login/oauth/access_token',
3737
{
@@ -43,23 +43,23 @@ export async function onRequest(context) {
4343
},
4444
body: JSON.stringify({ client_id, client_secret, code }),
4545
},
46-
)
47-
const result = await response.json()
46+
);
47+
const result = await response.json();
4848
if (result.error) {
49-
return new Response(renderBody('error', result), { status: 401 })
49+
return new Response(renderBody('error', result), { status: 401 });
5050
}
51-
const token = result.access_token
52-
const provider = 'github'
51+
const token = result.access_token;
52+
const provider = 'github';
5353
const responseBody = renderBody('success', {
5454
token,
5555
provider,
56-
})
57-
return new Response(responseBody, { status: 200 })
56+
});
57+
return new Response(responseBody, { status: 200 });
5858

5959
} catch (error) {
60-
console.error(error)
60+
console.error(error);
6161
return new Response(error.message, {
6262
status: 500,
63-
})
63+
});
6464
}
6565
}

0 commit comments

Comments
 (0)