Skip to content

Commit 761b726

Browse files
committed
add: allow non-logged in users to make requests
1 parent cfbb839 commit 761b726

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/services/github.service.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ export async function getGitTree(SHA: string, recursive = false) {
1919
const authStore = useAuthStore();
2020

2121
try {
22-
const response = await axios.get<TreeResponse>(url.toString(), {
23-
headers: {
24-
Accept: "application/vnd.github+json",
25-
Authorization: `Bearer ${authStore.access_token}`,
26-
},
27-
});
22+
const headers: { [index: string]: string } = {
23+
Accept: "application/vnd.github+json",
24+
};
25+
if (authStore.access_token)
26+
headers.Authorization = `Bearer ${authStore.access_token}`;
27+
28+
const response = await axios.get<TreeResponse>(url.toString(), headers);
2829
console.log(response);
2930
return response.data;
3031
} catch (e: any) {
@@ -50,13 +51,13 @@ export async function getCommit(path: string) {
5051
const authStore = useAuthStore();
5152

5253
try {
53-
console.log(endpoint.toString());
54-
const response = await axios.get<CommitList>(endpoint.toString(), {
55-
headers: {
56-
Accept: "application/vnd.github+json",
57-
Authorization: `Bearer ${authStore.access_token}`,
58-
},
59-
});
54+
const headers: { [index: string]: string } = {
55+
Accept: "application/vnd.github+json",
56+
};
57+
if (authStore.access_token)
58+
headers.Authorization = `Bearer ${authStore.access_token}`;
59+
60+
const response = await axios.get<CommitList>(endpoint.toString(), headers);
6061
console.log(response);
6162
console.log(`Retrieved commit ${response.data[0].sha}`);
6263
return response.data[0];

src/stores/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defineStore } from "pinia";
22

33
export type AuthStore = {
4-
access_token: string | null;
4+
access_token: string | boolean | null;
55
};
66

77
export const useAuthStore = defineStore("auth", {

0 commit comments

Comments
 (0)