Skip to content

Commit db9571c

Browse files
authored
Version v0.4
- Use svelte kit node server as proxy to fractal-server - Use the node adapter to build the svelte server - Update api packages to use server side fetch instead of client side fetch - General updates to UI and data management with new SSR driven pattern
2 parents 170714f + cd9ddba commit db9571c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1617
-656
lines changed

.env.development

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FRACTAL_SERVER_HOST=http://localhost:8000
2+
3+
# AUTH COOKIE
4+
AUTH_COOKIE_NAME=fastapiusersauth
5+
AUTH_COOKIE_SECURE=false
6+
AUTH_COOKIE_DOMAIN=localhost
7+
AUTH_COOKIE_PATH=/
8+
AUTH_COOKIE_MAX_AGE=1800
9+
AUTH_COOKIE_SAME_SITE=lax
10+
AUTH_COOKIE_HTTP_ONLY=true

package-lock.json

Lines changed: 240 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"devDependencies": {
1616
"@playwright/test": "^1.32.3",
1717
"@sveltejs/adapter-auto": "^2.0.0",
18+
"@sveltejs/adapter-node": "^1.2.4",
1819
"@sveltejs/kit": "^1.15.7",
1920
"eslint": "^8.38.0",
2021
"eslint-config-prettier": "^8.3.0",
@@ -29,6 +30,7 @@
2930
"type": "module",
3031
"dependencies": {
3132
"@vincjo/datatables": "^1.6.0",
33+
"jose": "^4.14.4",
3234
"sweetalert2": "^11.4.37"
3335
}
3436
}

src/hooks.server.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { FRACTAL_SERVER_HOST } from '$env/static/private'
2+
3+
export async function handle({ event, resolve }) {
4+
console.log(`[${event.request.method}] - ${event.url.pathname}`)
5+
6+
if (event.url.pathname == '/' || event.url.pathname.startsWith('/auth')) {
7+
console.log('Public page - No auth required')
8+
return await resolve(event)
9+
}
10+
11+
// Authentication guard
12+
const fastApiUsersAuth = event.cookies.get('fastapiusersauth')
13+
if (!fastApiUsersAuth) {
14+
console.log('Authentication required - No auth cookie found - Redirecting to login')
15+
return new Response(null, { status: 302, headers: { location: '/auth/login' } })
16+
}
17+
18+
const whoami = await event.fetch(`${FRACTAL_SERVER_HOST}/auth/whoami`)
19+
if (whoami.ok) {
20+
return await resolve(event)
21+
} else {
22+
console.log('Validation of authentication - Error loading user info')
23+
return new Response(null, { status: 302, headers: { location: '/auth/login' } })
24+
}
25+
}

0 commit comments

Comments
 (0)