-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
260 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 0 additions & 83 deletions
83
examples/with-supabase/app/_examples/protected-route/page.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs' | ||
import { cookies } from 'next/headers' | ||
import { NextResponse } from 'next/server' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export async function POST(request: Request) { | ||
const requestUrl = new URL(request.url) | ||
const formData = await request.formData() | ||
const email = String(formData.get('email')) | ||
const password = String(formData.get('password')) | ||
const supabase = createRouteHandlerClient({ cookies }) | ||
|
||
const { error } = await supabase.auth.signInWithPassword({ | ||
email, | ||
password, | ||
}) | ||
|
||
if (error) { | ||
return NextResponse.redirect( | ||
`${requestUrl.origin}/login?error=Could not authenticate user`, | ||
{ | ||
// a 301 status is required to redirect from a POST to a GET route | ||
status: 301, | ||
} | ||
) | ||
} | ||
|
||
return NextResponse.redirect(requestUrl.origin, { | ||
// a 301 status is required to redirect from a POST to a GET route | ||
status: 301, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs' | ||
import { cookies } from 'next/headers' | ||
import { NextResponse } from 'next/server' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export async function POST(request: Request) { | ||
const requestUrl = new URL(request.url) | ||
const supabase = createRouteHandlerClient({ cookies }) | ||
|
||
await supabase.auth.signOut() | ||
|
||
return NextResponse.redirect(`${requestUrl.origin}/login`, { | ||
// a 301 status is required to redirect from a POST to a GET route | ||
status: 301, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs' | ||
import { cookies } from 'next/headers' | ||
import { NextResponse } from 'next/server' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export async function POST(request: Request) { | ||
const requestUrl = new URL(request.url) | ||
const formData = await request.formData() | ||
const email = String(formData.get('email')) | ||
const password = String(formData.get('password')) | ||
const supabase = createRouteHandlerClient({ cookies }) | ||
|
||
const { error } = await supabase.auth.signUp({ | ||
email, | ||
password, | ||
options: { | ||
emailRedirectTo: `${requestUrl.origin}/auth/callback`, | ||
}, | ||
}) | ||
|
||
if (error) { | ||
return NextResponse.redirect( | ||
`${requestUrl.origin}/login?error=Could not authenticate user`, | ||
{ | ||
// a 301 status is required to redirect from a POST to a GET route | ||
status: 301, | ||
} | ||
) | ||
} | ||
|
||
return NextResponse.redirect( | ||
`${requestUrl.origin}/login?message=Check email to continue sign in process`, | ||
{ | ||
// a 301 status is required to redirect from a POST to a GET route | ||
status: 301, | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use client' | ||
|
||
import { useSearchParams } from 'next/navigation' | ||
|
||
export default function Messages() { | ||
const searchParams = useSearchParams() | ||
const error = searchParams.get('error') | ||
const message = searchParams.get('message') | ||
return ( | ||
<> | ||
{error && ( | ||
<p className="mt-4 p-4 bg-neutral-900 text-neutral-300 text-center"> | ||
{error} | ||
</p> | ||
)} | ||
{message && ( | ||
<p className="mt-4 p-4 bg-neutral-900 text-neutral-300 text-center"> | ||
{message} | ||
</p> | ||
)} | ||
</> | ||
) | ||
} |
Oops, something went wrong.