Skip to content

Commit 42510c1

Browse files
authored
Merge pull request #43 from osusach/staging
chore: release updates from staging to master
2 parents 1b09b8d + b6b2d94 commit 42510c1

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

actions/auth.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ import { redirect } from "next/navigation";
55

66
import { createClient } from "@/utils/supabase/server";
77

8-
export async function signInWithGoogle() {
8+
export async function signInWithGoogle({ nextUrl }: { nextUrl?: string } = {}) {
99
const supabase = await createClient();
1010
const origin = (await headers()).get("origin");
11-
const redirectTo = `${origin}/auth/callback`;
11+
12+
// Redirect config
13+
const baseUrl = `${origin}/auth/callback`;
14+
const searchParams = new URLSearchParams();
15+
16+
if (nextUrl) {
17+
searchParams.append("next_url", nextUrl);
18+
}
19+
20+
const queryString = searchParams.toString();
21+
const redirectTo = queryString ? `${baseUrl}?${queryString}` : baseUrl;
1222

1323
const { data, error } = await supabase.auth.signInWithOAuth({
1424
options: {

app/(auth-pages)/sign-in/page.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
"use client";
22

33
import Image from "next/image";
4+
import { use } from "react";
45

56
import { Button } from "@/components/ui/button";
67
import { signInWithGoogle } from "@/actions/auth";
78

8-
export default function Login() {
9+
type SearchParams = Promise<{ [key: string]: string | string[] | undefined }>;
10+
11+
export default function SignInPage(props: { searchParams: SearchParams }) {
12+
const searchParams = use(props.searchParams);
13+
const redirect = searchParams.redirect as string | undefined;
14+
915
const handleSignIn = async () => {
10-
await signInWithGoogle();
16+
await signInWithGoogle({ nextUrl: redirect });
1117
};
1218

1319
return (

app/auth/callback/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createClient } from "@/utils/supabase/server";
55
export async function GET(request: Request) {
66
const { searchParams, origin } = new URL(request.url);
77
const code = searchParams.get("code");
8-
const next = searchParams.get("next") ?? "/dashboard";
8+
const next = searchParams.get("next_url") ?? "/get-started";
99

1010
if (code) {
1111
const supabase = await createClient();

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dev": "next dev --turbo",
77
"format": "prettier . --write",
88
"format:check": "prettier . --check",
9+
"generate:types": "supabase gen types typescript --local > ./types/database.ts",
910
"build": "next build",
1011
"start": "next start",
1112
"lint": "next lint"

utils/supabase/middleware.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export const updateSession = async (request: NextRequest) => {
4040
);
4141

4242
if (isProtectedRoute && user.error) {
43-
return NextResponse.redirect(new URL("/sign-in", request.url));
43+
const redirectUrl = new URL("/sign-in", request.url);
44+
redirectUrl.searchParams.set("redirect", request.nextUrl.pathname);
45+
return NextResponse.redirect(redirectUrl);
4446
}
4547

4648
if (request.nextUrl.pathname === "/" && !user.error) {

0 commit comments

Comments
 (0)