Skip to content

Commit

Permalink
feat!: implement github login button ( without access code ).
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed May 8, 2023
1 parent e9c8dd5 commit 2b3ceac
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
17 changes: 4 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { env } from '$env/dynamic/private';

export const GH_STATE_COOKIE_NAME = 'gh_state';
export const GH_ACCESS_TOKEN_COOKIE_NAME = 'gh_token';

let GH_CLIENT_ID_;
let GH_CLIENT_SECRET_;
if (process.env) {
GH_CLIENT_ID_ = process.env['GH_CLIENT_ID'];
GH_CLIENT_SECRET_ = process.env['GH_CLIENT_SECRET'];
} else {
GH_CLIENT_ID_ = (Deno as any).env.get('GH_CLIENT_ID');
GH_CLIENT_SECRET_ = (Deno as any).env.get('GH_CLIENT_SECRET');
}

export const GH_CLIENT_ID = GH_CLIENT_ID_;
export const GH_CLIENT_SECRET = GH_CLIENT_SECRET_;
export const GH_CLIENT_ID = env['GH_CLIENT_ID'];
export const GH_CLIENT_SECRET = env['GH_CLIENT_SECRET'];
8 changes: 8 additions & 0 deletions src/routes/publish/github/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const csr = false;

import { GH_CLIENT_ID } from '../../../config';
import type { PageLoad } from './$types';

export const load = (({ params, url }) => {
return { GH_CLIENT_ID, state: crypto.randomUUID(), href: url.href };
}) satisfies PageLoad;
16 changes: 7 additions & 9 deletions src/routes/publish/github/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
// import { GH_CLIENT_ID } from '../../../config';
const props = { data: '', url: new URL('https://example.com') };
const GH_CLIENT_ID = '';
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
</script>

<h1 class="text-4xl text-center font-medium my-8 flex justify-center gap-8 items-center">
Expand All @@ -23,12 +23,10 @@

<div class="flex flex-col items-center mt-8">
<a
href={`https://github.com/login/oauth/authorize?client_id=${GH_CLIENT_ID}&state=${
props.data
}&scope=public_repo&redirect_uri=${encodeURIComponent(props.url.href)}/callback`}
href={`https://github.com/login/oauth/authorize?client_id=${data.GH_CLIENT_ID}&state=${
data.state
}&scope=public_repo&redirect_uri=${encodeURIComponent(data.href)}/auth_callback`}
>
<div class="btn btn-outline btn-success">Login to GitHub</div>

<!-- {GH_CLIENT_ID} -->
</a>
</div>
1 change: 1 addition & 0 deletions src/routes/publish/github/auth_callback/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Auth callback

0 comments on commit 2b3ceac

Please sign in to comment.