diff options
| author | Adam Soltys <[email protected]> | 2023-01-03 00:22:30 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-05 07:41:32 -0800 |
| commit | a657fab89a7de41f0a33389023166a6f7af6dbe6 (patch) | |
| tree | 77a485e5539be24542b38de582338946d317a4ce /src/routes/(app)/+layout.server.js | |
| parent | 9849f6c4431214665c47c43098d86112c93d8001 (diff) | |
| download | coinos-ui-a657fab89a7de41f0a33389023166a6f7af6dbe6.tar.gz coinos-ui-a657fab89a7de41f0a33389023166a6f7af6dbe6.zip | |
generate pubkey on register
Diffstat (limited to 'src/routes/(app)/+layout.server.js')
| -rw-r--r-- | src/routes/(app)/+layout.server.js | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/routes/(app)/+layout.server.js b/src/routes/(app)/+layout.server.js index 88ca1539..eef1bdec 100644 --- a/src/routes/(app)/+layout.server.js +++ b/src/routes/(app)/+layout.server.js @@ -1,18 +1,35 @@ import { error, redirect } from '@sveltejs/kit'; -import { get, post, auth } from '$lib/utils'; +import { get, post, auth, protectedRoutes } from '$lib/utils'; import { PUBLIC_BTC as btc } from '$env/static/public'; -export async function load({ cookies, locals, request, url, params }) { - url.pathname; +export async function load({ cookies, request, url, params }) { + let { pathname } = url; let token = cookies.get('token'); let rate, rates = { USD: 1 }, subject; - let { user } = locals; + let user; + if (token) { + try { + user = await get('/me', auth(cookies)); + } catch (e) {} + } + + if (user && ['/', '/login', '/register'].includes(pathname) && request.method === 'GET') + throw redirect(307, `/${user.username}/dashboard`); + + if ( + protectedRoutes.find((p) => pathname.match(p)) && + (!user || user.username !== params.username) + ) { + throw redirect(307, '/login'); + } + if (user) { - if (!user.pubkey && !url.pathname.includes('gen')) + if (!user.pubkey && !url.pathname.includes('gen')) { throw redirect(307, `/${user.username}/generate`); + } let account = user.accounts.find((a) => a.asset === btc && !a.pubkey); if (account) { let { id } = account; |
