-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client-side render dashboard and individual pages
Signed-off-by: Frank Noirot <[email protected]>
- Loading branch information
1 parent
a9493df
commit 9b5b4b5
Showing
5 changed files
with
52 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
/** @type {import('./$types').LayoutData} */ | ||
export const load = async ({ locals }) => { | ||
export const load = async ({ locals, cookies }) => { | ||
const token = cookies.get('__Secure-next-auth.session-token') | ||
|
||
return { | ||
user: !locals.user || 'error_code' in locals.user ? undefined : locals.user | ||
user: !locals.user || 'error_code' in locals.user ? undefined : locals.user, | ||
token | ||
} | ||
} |
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,33 @@ | ||
import { endpoints } from '$lib/endpoints.js' | ||
import type { Models } from '@kittycad/lib' | ||
import { error, redirect } from '@sveltejs/kit' | ||
|
||
export const csr = true | ||
|
||
/** @type {import('./$types').PageLoad} */ | ||
export async function load({ params, parent, fetch }) { | ||
const data = await parent() | ||
|
||
if (!data.token) { | ||
throw redirect(301, '/') | ||
} | ||
|
||
const response = await fetch(endpoints.view(params.modelId), { | ||
headers: { | ||
Authorization: 'Bearer ' + data.token | ||
} | ||
}) | ||
|
||
if (response.status >= 400 && response.status < 500) { | ||
throw error( | ||
response.status, | ||
'Model could not be found or you do not have permission to view it' | ||
) | ||
} | ||
|
||
if (!response.ok) { | ||
throw error(response.status, 'Failed to fetch model') | ||
} | ||
|
||
return (await response.json()) as Models['TextToCad_type'] | ||
} |