Skip to content

Commit

Permalink
fix middleware bug blocking login
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktaubeneck committed Jan 17, 2024
1 parent 5a001df commit 438680b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions server/app/login/GitHubOAuthComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ export default function GitHubOAuthComponent() {
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
);

let url = process?.env?.NEXT_PUBLIC_SITE_URL;
let url =
process?.env?.NEXT_PUBLIC_SITE_URL ?? // Set this to your site URL in production env.
process?.env?.NEXT_PUBLIC_VERCEL_URL ?? // Automatically set by Vercel.
"http://localhost:3000/";
// Make sure to include `https://` when not localhost.
url = url.includes("http") ? url : `https://${url}`;
// Make sure to include a trailing `/`.
url = url.charAt(url.length - 1) === "/" ? url : `${url}/`;

const handleGitHubLogin = async () => {
const { error } = await supabase.auth.signInWithOAuth({
provider: "github",
options: {
redirectTo: `${url}/auth/callback`,
redirectTo: `${url}auth/callback`,
},
});

Expand Down
4 changes: 2 additions & 2 deletions server/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export async function middleware(request: NextRequest) {
data: { user },
} = await supabase.auth.getUser();

if (!user && request.nextUrl.pathname !== "/") {
const allowedPathsRegex = new RegExp(`^(/|/login|/auth/callback|/docs/.+)$`);
if (!user && !allowedPathsRegex.test(request.nextUrl.pathname)) {
const url = request.nextUrl.clone();

url.pathname = `/404`;
return NextResponse.rewrite(url);
}
Expand Down

0 comments on commit 438680b

Please sign in to comment.