Skip to content

Commit 86f7032

Browse files
committed
testing
1 parent 6391d2a commit 86f7032

File tree

4 files changed

+58
-83
lines changed

4 files changed

+58
-83
lines changed

apps/website/app/access-token/page.tsx

Lines changed: 0 additions & 61 deletions
This file was deleted.

apps/website/app/api/access-token/route.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@ export const POST = async (request: Request) => {
1616
const body = await request.json();
1717
const validatedData = requestSchema.parse(body);
1818

19-
const supabase = await createClient();
20-
21-
let query = supabase
22-
.from("access-token")
23-
.select("access-token, code, state, created_date")
24-
.order("created_date", { ascending: false })
25-
.limit(1);
26-
27-
if (validatedData.code) {
28-
query = query.eq("code", validatedData.code);
29-
} else if (validatedData.state) {
30-
query = query.eq("state", validatedData.state);
31-
}
19+
// const supabase = await createClient();
20+
21+
// let query = supabase
22+
// .from("access-token")
23+
// .select("access-token, code, state, created_date")
24+
// .order("created_date", { ascending: false })
25+
// .limit(1);
26+
27+
// if (validatedData.code) {
28+
// query = query.eq("code", validatedData.code);
29+
// } else if (validatedData.state) {
30+
// query = query.eq("state", validatedData.state);
31+
// }
32+
33+
// const { data, error } = await query;
3234

33-
const { data, error } = await query;
35+
const data = [{ "access-token": "dummy data" }];
36+
const error = null;
3437

3538
if (error) {
3639
return NextResponse.json(

apps/website/app/auth/github/page.tsx

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,42 @@ type Props = {
44
searchParams: Promise<{ code?: string; state?: string }>;
55
};
66

7+
const API_URL =
8+
process.env.NODE_ENV === "development"
9+
? "http://localhost:3000/api/access-token"
10+
: "https://discoursegraphs.com/api/access-token";
11+
12+
console.log("API_URL", API_URL);
13+
714
const Page = async ({ searchParams }: Props) => {
815
const { code, state } = await searchParams;
916

10-
// TODO zod validate the response
11-
const { accessToken: accessTokenByCode } = await fetch("/api/access-token", {
12-
method: "POST",
13-
body: JSON.stringify({ code }),
14-
}).then((r) => r.json());
17+
try {
18+
// TODO zod validate the response
19+
const response = await fetch(API_URL, {
20+
method: "POST",
21+
body: JSON.stringify({ code }),
22+
});
23+
24+
if (!response.ok) {
25+
throw new Error(`HTTP error! status: ${response.status}`);
26+
}
27+
28+
const responseText = await response.text();
29+
30+
if (!responseText) {
31+
throw new Error("Empty response received");
32+
}
33+
34+
const accessTokenByCode = JSON.parse(responseText);
1535

16-
return (
17-
<ClientCallbackHandler accessToken={accessTokenByCode} state={state} />
18-
);
36+
return (
37+
<ClientCallbackHandler accessToken={accessTokenByCode} state={state} />
38+
);
39+
} catch (error) {
40+
console.error("Error in GitHub auth callback:", error);
41+
throw error;
42+
}
1943
};
2044

2145
export default Page;

apps/website/app/auth/layout.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const RootLayout = ({ children }: { children: React.ReactNode }) => {
2+
return (
3+
<html lang="en">
4+
<body>{children}</body>
5+
</html>
6+
);
7+
};
8+
9+
export default RootLayout;

0 commit comments

Comments
 (0)