-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
254 additions
and
135 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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 @@ | ||
// src/app.d.ts | ||
|
||
import { SupabaseClient, Session } from '@supabase/supabase-js' | ||
|
||
declare global { | ||
namespace App { | ||
interface Locals { | ||
supabase: SupabaseClient | ||
getSession(): Promise<Session | null> | ||
} | ||
interface PageData { | ||
session: Session | null | ||
} | ||
// interface Error {} | ||
// interface Platform {} | ||
} | ||
} |
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,28 @@ | ||
// src/hooks.server.ts | ||
import { PUBLIC_SUPABASE_URL, PUBLIC_SUPABASE_ANON_KEY } from '$env/static/public' | ||
import { createSupabaseServerClient } from '@supabase/auth-helpers-sveltekit' | ||
import type { Handle } from '@sveltejs/kit' | ||
|
||
export const handle: Handle = async ({ event, resolve }) => { | ||
event.locals.supabase = createSupabaseServerClient({ | ||
supabaseUrl: PUBLIC_SUPABASE_URL, | ||
supabaseKey: PUBLIC_SUPABASE_ANON_KEY, | ||
event, | ||
}) | ||
|
||
/** | ||
* A convenience helper so we can just call await getSession() instead const { data: { session } } = await supabase.auth.getSession() | ||
*/ | ||
event.locals.getSession = async () => { | ||
const { | ||
data: { session }, | ||
} = await event.locals.supabase.auth.getSession() | ||
return session | ||
} | ||
|
||
return resolve(event, { | ||
filterSerializedResponseHeaders(name) { | ||
return name === 'content-range' | ||
}, | ||
}) | ||
} |
Empty file.
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,6 @@ | ||
// src/routes/+layout.server.ts | ||
export const load = async ({ locals: { getSession } }) => { | ||
return { | ||
session: await getSession(), | ||
} | ||
} |
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,19 +1,67 @@ | ||
<script> | ||
import "../app.css"; | ||
import Nav from '../components/nav.svelte'; | ||
</script> | ||
import '../app.css'; | ||
import Nav from '../components/nav.svelte'; | ||
<style> | ||
:global(body) { | ||
/* background-color: #0e0719; */ | ||
background-color: #F3F4F6; | ||
} | ||
</style> | ||
import { invalidate } from '$app/navigation'; | ||
import { onMount } from 'svelte'; | ||
export let data; | ||
let { supabase, session } = data; | ||
$: ({ supabase, session } = data); | ||
onMount(() => { | ||
const { data } = supabase.auth.onAuthStateChange((event, _session) => { | ||
if (_session?.expires_at !== session?.expires_at) { | ||
invalidate('supabase:auth'); | ||
} | ||
}); | ||
return () => data.subscription.unsubscribe(); | ||
}); | ||
async function currentUser() { | ||
try { | ||
const { data } = await supabase.auth.getUser(); | ||
return data.user; | ||
} catch (error) { | ||
console.error('Error fetching user:', error); | ||
return null; | ||
} | ||
} | ||
async function signInWithGithub() { | ||
const { data, error } = await supabase.auth.signInWithOAuth({ | ||
provider: 'github', | ||
options: { | ||
redirectTo: '/' | ||
} | ||
}); | ||
console.log(error); | ||
} | ||
async function signOut() { | ||
const { error } = await supabase.auth.signOut(); | ||
if (!error) { | ||
// 로그아웃 성공 후 페이지 새로고침 | ||
location.reload(); | ||
} else { | ||
// 오류 처리 (필요한 경우) | ||
console.error('Logout failed:', error); | ||
} | ||
} | ||
</script> | ||
<div class="mx-auto"> | ||
<Nav></Nav> | ||
<Nav {signInWithGithub} {signOut} {currentUser}></Nav> | ||
</div> | ||
<div class="max-w-6xl mx-auto mt-32"> | ||
<slot /> | ||
</div> | ||
<slot /> | ||
</div> | ||
<style> | ||
:global(body) { | ||
/* background-color: #0e0719; */ | ||
background-color: #f3f4f6; | ||
} | ||
</style> |
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,20 @@ | ||
// src/routes/+layout.ts | ||
import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_SUPABASE_URL } from '$env/static/public' | ||
import { createSupabaseLoadClient } from '@supabase/auth-helpers-sveltekit' | ||
|
||
export const load = async ({ fetch, data, depends }) => { | ||
depends('supabase:auth') | ||
|
||
const supabase = createSupabaseLoadClient({ | ||
supabaseUrl: PUBLIC_SUPABASE_URL, | ||
supabaseKey: PUBLIC_SUPABASE_ANON_KEY, | ||
event: { fetch }, | ||
serverSession: data.session, | ||
}) | ||
|
||
const { | ||
data: { session }, | ||
} = await supabase.auth.getSession() | ||
|
||
return { supabase, session } | ||
} |
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