Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
testing
  • Loading branch information
mdroidian committed Jun 16, 2025
commit 86f70328112d6e0dc6d0ab17c1f4836a912b3140
61 changes: 0 additions & 61 deletions apps/website/app/access-token/page.tsx

This file was deleted.

31 changes: 17 additions & 14 deletions apps/website/app/api/access-token/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ export const POST = async (request: Request) => {
const body = await request.json();
const validatedData = requestSchema.parse(body);

const supabase = await createClient();

let query = supabase
.from("access-token")
.select("access-token, code, state, created_date")
.order("created_date", { ascending: false })
.limit(1);

if (validatedData.code) {
query = query.eq("code", validatedData.code);
} else if (validatedData.state) {
query = query.eq("state", validatedData.state);
}
// const supabase = await createClient();

// let query = supabase
// .from("access-token")
// .select("access-token, code, state, created_date")
// .order("created_date", { ascending: false })
// .limit(1);

// if (validatedData.code) {
// query = query.eq("code", validatedData.code);
// } else if (validatedData.state) {
// query = query.eq("state", validatedData.state);
// }

// const { data, error } = await query;

const { data, error } = await query;
const data = [{ "access-token": "dummy data" }];
const error = null;

if (error) {
return NextResponse.json(
Expand Down
40 changes: 32 additions & 8 deletions apps/website/app/auth/github/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,42 @@ type Props = {
searchParams: Promise<{ code?: string; state?: string }>;
};

const API_URL =
process.env.NODE_ENV === "development"
? "http://localhost:3000/api/access-token"
: "https://discoursegraphs.com/api/access-token";

console.log("API_URL", API_URL);

const Page = async ({ searchParams }: Props) => {
const { code, state } = await searchParams;

// TODO zod validate the response
const { accessToken: accessTokenByCode } = await fetch("/api/access-token", {
method: "POST",
body: JSON.stringify({ code }),
}).then((r) => r.json());
try {
// TODO zod validate the response
const response = await fetch(API_URL, {
method: "POST",
body: JSON.stringify({ code }),
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const responseText = await response.text();

if (!responseText) {
throw new Error("Empty response received");
}

const accessTokenByCode = JSON.parse(responseText);

return (
<ClientCallbackHandler accessToken={accessTokenByCode} state={state} />
);
return (
<ClientCallbackHandler accessToken={accessTokenByCode} state={state} />
);
} catch (error) {
console.error("Error in GitHub auth callback:", error);
throw error;
}
};

export default Page;
9 changes: 9 additions & 0 deletions apps/website/app/auth/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const RootLayout = ({ children }: { children: React.ReactNode }) => {
return (
<html lang="en">
<body>{children}</body>
</html>
);
};

export default RootLayout;