Skip to content

Commit

Permalink
refactor(auth): implement client-side github oauth flow to fix CORS i…
Browse files Browse the repository at this point in the history
…ssue
  • Loading branch information
JaleelB committed Jul 26, 2024
1 parent 49c5d1b commit a0fc8cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
30 changes: 2 additions & 28 deletions app/(auth)/signin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,34 +156,8 @@ export default function SignInPage() {
<Separator className="my-4 h-[1px] w-full shrink-0 bg-border" />

<div className="space-y-4">
{/* <Link
href="/api/login/google"
className={cn(
buttonVariants({
variant: "outline",
}),
"w-full",
)}
>
<Icons.google className="mr-2 h-4 w-4" />
Sign in with Google
</Link> */}
<OAuthButton provider="google">
<Icons.google className="mr-2 h-4 w-4" />
Sign in with Google
</OAuthButton>
<Link
href="/api/login/github"
className={cn(
buttonVariants({
variant: "outline",
}),
"w-full",
)}
>
<Icons.github className="mr-2 h-4 w-4" />
Sign in with GitHub
</Link>
<OAuthButton provider="google">Sign in with Google</OAuthButton>
<OAuthButton provider="github">Sign in with Github</OAuthButton>
</div>
<div className="text-center text-sm">
Don&apos;t have an account?{" "}
Expand Down
4 changes: 3 additions & 1 deletion app/api/login/github/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ export async function GET(): Promise<Response> {
sameSite: "lax",
});

return Response.redirect(url);
// return Response.redirect(url);
// Instead of redirecting, return the URL to the client
return Response.json({ url: url.toString() });
}
7 changes: 7 additions & 0 deletions components/oauth-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from "react";
import { cn } from "@/lib/utils";
import { buttonVariants } from "@/components/ui/button";
import { LoaderButton } from "./loader-button";
import { Icons } from "./icons";

export function OAuthButton({
provider,
Expand Down Expand Up @@ -42,6 +43,12 @@ export function OAuthButton({
)}
type="submit"
>
{provider === "google" && !isLoading && (
<Icons.google className="mr-2 h-4 w-4" />
)}
{provider === "github" && !isLoading && (
<Icons.github className="mr-2 h-4 w-4" />
)}
{children}
</LoaderButton>
);
Expand Down

0 comments on commit a0fc8cf

Please sign in to comment.