-
Notifications
You must be signed in to change notification settings - Fork 1
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
Bui Thanh Luan
committed
Oct 10, 2022
1 parent
5fb3589
commit b248f57
Showing
12 changed files
with
839 additions
and
55 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 |
---|---|---|
|
@@ -8,3 +8,6 @@ node_modules | |
!.env.example | ||
.vercel | ||
.output | ||
|
||
# key | ||
firebaseKey.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { initializeApp, credential } from 'firebase-admin' | ||
import { PATH_TO_KEY } from '$env/static/private' | ||
|
||
export const app = initializeApp({ | ||
credential: credential.cert(PATH_TO_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 @@ | ||
<h1>Login</h1> |
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,5 +1,32 @@ | ||
import type { PageServerLoad } from './$types'; | ||
import { redirect } from '@sveltejs/kit' | ||
import type { PageServerLoad } from './$types' | ||
import { getAuth } from 'firebase-admin/auth' | ||
|
||
export const load: PageServerLoad = async () => { | ||
return {}; | ||
}; | ||
import { app } from '$lib/firebase' | ||
import { prisma } from '$lib/prisma' | ||
|
||
export const load: PageServerLoad = async ({ cookies, locals: { locale } }) => { | ||
try { | ||
const token = cookies.get('token') | ||
if (!token) { | ||
throw redirect(307, `/${locale}/login`) | ||
} | ||
const { uid } = await getAuth(app).verifyIdToken( | ||
'eyJhbGciOiJSUzI1NiIsImtpZCI6Ijk5NjJmMDRmZWVkOTU0NWNlMjEzNGFiNTRjZWVmNTgxYWYyNGJhZmYiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiTHXDom4gQsO5aSIsInBpY3R1cmUiOiJodHRwczovL2xoMy5nb29nbGV1c2VyY29udGVudC5jb20vYS9BSXRidm1tWnZ5X0lRX2N6aFdfUmFtSVlXdEc2aDV2bjI0VVg0eFlOME5xXz1zOTYtYyIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9iYXlxdWFtb24iLCJhdWQiOiJiYXlxdWFtb24iLCJhdXRoX3RpbWUiOjE2NjUzOTYyODEsInVzZXJfaWQiOiJqckdlQzVLUGgzUkVyTUVhZU5NU1hZa0hMSUEyIiwic3ViIjoianJHZUM1S1BoM1JFck1FYWVOTVNYWWtITElBMiIsImlhdCI6MTY2NTM5NjI4MSwiZXhwIjoxNjY1Mzk5ODgxLCJlbWFpbCI6Imx1YW4udnkueWJAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZ29vZ2xlLmNvbSI6WyIxMDI4NzI3MDUwODE1Mjg5NjM5MDIiXSwiZW1haWwiOlsibHVhbi52eS55YkBnbWFpbC5jb20iXX0sInNpZ25faW5fcHJvdmlkZXIiOiJnb29nbGUuY29tIn19.DOi7Usu0Gg4V8765U6xf-gEFnSeplf05IUdaeQV0LiH2TPYvaVgghVZFHT55iPn86dDBgmx8Raal5iC_7t_8QxrHZfGH0Noe7YuHyXivItCvC2FphfaVBQ4lM0-SE5axZgqltckj24qLIMbQ6jJs9HkwJLMzR2epS0UOpoCMtBfFe8SdAH32L8OuXrBrGTg8wVxCkRP7-_Dc5KxhBCkiKF9K46xyxWcWhhphR9btHvZyKEwMM4sAJzdFuqHdEX1Xgl63aO9ol541EGG-mlpt4XGk8ASPHYHlzzhowIHK_LDl5eWTua_plv9Ra30BZmdx6K7zs7se7p6Wqxiio_ajZQ', | ||
true, | ||
) | ||
console.log(uid) | ||
|
||
return { | ||
user: prisma.user.findFirst({ | ||
where: { | ||
uid: '12345', | ||
}, | ||
}), | ||
} | ||
} catch (e) { | ||
console.log(e) | ||
|
||
throw redirect(307, `/${locale}/login`) | ||
} | ||
} |
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,7 +1,8 @@ | ||
<script lang="ts"> | ||
import type { PageData } from './$types'; | ||
export let data: PageData; | ||
import type { PageData } from './$types' | ||
export let data: PageData | ||
</script> | ||
|
||
<h1>Profile</h1> | ||
<h1>Profile</h1> | ||
{JSON.stringify(data, null, 2)} |
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,5 +1,5 @@ | ||
import type { PageLoad } from './$types'; | ||
import type { PageLoad } from './$types' | ||
|
||
export const load: PageLoad = async () => { | ||
return {}; | ||
}; | ||
export const load: PageLoad = async ({ data }) => { | ||
return data | ||
} |
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,8 +1,13 @@ | ||
import { readable } from 'svelte/store'; | ||
import { getAuth, type User } from 'firebase/auth'; | ||
import { readable } from 'svelte/store' | ||
import { getAuth, type User } from 'firebase/auth' | ||
import { browser } from '$app/environment' | ||
|
||
export const user = readable<User | null>(null, (set) => { | ||
getAuth().onAuthStateChanged((user) => { | ||
set(user); | ||
}); | ||
}); | ||
getAuth().onAuthStateChanged(async (user) => { | ||
const token = await user?.getIdToken() | ||
if (browser) { | ||
document.cookie = `token=${token ?? ''}; path=/` | ||
} | ||
set(user) | ||
}) | ||
}) |
Oops, something went wrong.