Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
feat: migrate authentication (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cahllagerfeld authored Jan 26, 2022
1 parent 81dfab9 commit 9975593
Show file tree
Hide file tree
Showing 11 changed files with 1,041 additions and 197 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_TOKEN=<Your-Super-Secret-Github-Token>
1,046 changes: 1,012 additions & 34 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
},
"type": "module",
"dependencies": {
"cookie": "^0.4.1"
"octokit": "^1.7.1"
}
}
15 changes: 0 additions & 15 deletions src/hooks.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/lib/components/nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@
<a href="/">
<img src="/images/hubber.png" class="object-contain w-12" alt="hubber" />
</a>
<a rel="external" href="/logout">
<Button label="Sign Out" variant="primary" />
</a>
</nav>
48 changes: 3 additions & 45 deletions src/lib/types/github.type.ts → src/lib/types/github.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,6 @@ export type Label = {
description: string;
};

export type Assignee = {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean;
};

export type Assignee2 = {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean;
};

export type Reactions = {
url: string;
total_count: number;
Expand Down Expand Up @@ -99,8 +57,8 @@ export type Item = {
labels: Label[];
state: string;
locked: boolean;
assignee: Assignee;
assignees: Assignee2[];
assignee?: any;
assignees: any[];
milestone?: any;
comments: number;
created_at: Date;
Expand All @@ -115,7 +73,7 @@ export type Item = {
score: number;
};

export type GithubResponse = {
export type IssueResponse = {
total_count: number;
incomplete_results: boolean;
items: Item[];
Expand Down
15 changes: 15 additions & 0 deletions src/routes/api/get-issues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { RequestHandler } from '@sveltejs/kit';
import { Octokit } from 'octokit';

export const get: RequestHandler = async () => {
const token = import.meta.env.VITE_TOKEN;
if (!token) return { status: 500, body: { message: 'please provide a token' } };
const octokit = new Octokit({ auth: token });
const response = await octokit.request('GET /search/issues', {
q: 'is:issue is:open label:"good first issue" org:EddieHubCommunity no:assignee',
});
return {
status: 200,
body: response.data,
};
};
36 changes: 0 additions & 36 deletions src/routes/api/login.ts

This file was deleted.

30 changes: 0 additions & 30 deletions src/routes/auth.svelte

This file was deleted.

28 changes: 9 additions & 19 deletions src/routes/index.svelte
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
<script lang="ts" context="module">
import type { Load } from '@sveltejs/kit';
import type { Item } from '../lib/types/github.type';
export const load: Load = async ({ session, fetch }) => {
if (!session.token) {
return {
status: 302,
redirect: 'auth',
};
}
const res = await fetch(
'https://api.github.com/search/issues?q=is:issue%20is:open%20label:%22good%20first%20issue%22%20org:EddieHubCommunity%20no:assignee',
{
headers: {
Authorization: `token ${session.token}`,
},
},
);
const res = await fetch('/api/get-issues');
if (res.ok) {
const data = await res.json();
return {
props: {
issues: data.items as Item[],
data: data as IssueResponse,
},
};
}
const data = await res.json();
return {
error: data.message,
};
};
</script>

<script lang="ts">
import IssueCard from '../lib/components/issue-card.svelte';
export let issues: Item[];
import type { IssueResponse } from '../lib/types/github.types';
export let data: IssueResponse;
</script>

<div class="space-y-4">
{#each issues as issue}
{#each data.items as issue}
<IssueCard {issue} />
{/each}
</div>
14 changes: 0 additions & 14 deletions src/routes/logout.ts

This file was deleted.

0 comments on commit 9975593

Please sign in to comment.