-
Notifications
You must be signed in to change notification settings - Fork 25
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
1 parent
9dea297
commit 51722ad
Showing
10 changed files
with
196 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
SUPABASE_URL=http://127.0.0.1:54321 | ||
SUPABASE_ANON_KEY= | ||
VITE_SUPABASE_URL=http://127.0.0.1:54321 | ||
VITE_SUPABASE_ANON_KEY= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { supabase } from "../utils/supabase"; | ||
|
||
export const UserController = { | ||
async get() { | ||
const { data, error } = await supabase.auth.getUser() | ||
|
||
if( error !== null ) { | ||
throw error | ||
} | ||
|
||
return data.user | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
import { createFileRoute, useParams } from '@tanstack/react-router'; | ||
import { createFileRoute } from '@tanstack/react-router'; | ||
import { supabase } from '../../utils/supabase'; | ||
|
||
export const Route = createFileRoute('/events/$eventId')({ | ||
loader: async ({ params: { eventId } }) => { | ||
const { data, error } = await supabase | ||
.from('events') | ||
.select('*') | ||
.eq('id', eventId) | ||
.single() | ||
|
||
if (error !== null) { | ||
throw error | ||
} | ||
|
||
return { event: data } | ||
}, | ||
component: EventDetails | ||
}) | ||
|
||
function EventDetails() { | ||
const { eventId } = useParams({ strict: false }) | ||
return <div>Event {eventId}</div> | ||
const { event } = Route.useLoaderData() | ||
return ( | ||
<div> | ||
<div>Event ID: {event.id}</div> | ||
<div>Event Name: {event.name}</div> | ||
<div>Event Description: {event.description}</div> | ||
</div> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createFileRoute } from '@tanstack/react-router' | ||
import { useState } from 'react' | ||
import { supabase } from '../utils/supabase' | ||
|
||
export const Route = createFileRoute('/login')({ | ||
component: LoginPage, | ||
validateSearch: (search: Record<string, unknown>) => { | ||
return { | ||
redirect: (search.redirect as string) || '/', | ||
} | ||
}, | ||
}) | ||
|
||
function LoginPage() { | ||
const [email, setEmail] = useState('') | ||
const [password, setPassword] = useState('') | ||
const { redirect: redirectUrl } = Route.useSearch() | ||
|
||
async function login() { | ||
const { data: { session }, error } = await supabase.auth.signInWithPassword({ | ||
email, | ||
password | ||
}) | ||
|
||
if (error !== null) { | ||
throw error | ||
} | ||
|
||
if (session !== null) { | ||
window.location.href = redirectUrl | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
<label>Email: </label> | ||
<input className='border' type="email" onChange={(e) => { setEmail(e.target.value) }} /> | ||
<label>Password:</label> | ||
<input className='border' type="password" onChange={(e) => { setPassword(e.target.value) }} /> | ||
<button onClick={login}>Login</button> | ||
</div> | ||
) | ||
|
||
} |
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,22 @@ | ||
import { ParsedLocation, redirect } from "@tanstack/react-router"; | ||
import { supabase } from "./supabase"; | ||
|
||
export async function AuthGuard({ location }: { location: ParsedLocation }) { | ||
const { data: { session }, error } = await supabase.auth.getSession() | ||
|
||
if( error !== null ) { | ||
throw error | ||
} | ||
|
||
if (session === null) { | ||
throw redirect({ | ||
to: '/login', | ||
search: { | ||
// Use the current location to power a redirect after login | ||
// (Do not use `router.state.resolvedLocation` as it can | ||
// potentially lag behind the actual current location) | ||
redirect: location.href, | ||
}, | ||
}) | ||
} | ||
} |
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