diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..b073244 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,58 @@ +name: Docker Build and Publish + +on: + push: + branches: [ "main" ] + tags: [ "v*.*.*" ] + pull_request: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 791b82a..226ebaf 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -1,34 +1,33 @@ export let requestIp: string; -import { type Handle } from '@sveltejs/kit'; -import { dev } from '$app/environment'; -import { createInstance } from '$lib/pocketbase'; +import { type Handle } from "@sveltejs/kit"; +import { dev } from "$app/environment"; +import { createInstance } from "$lib/pocketbase"; export const handle: Handle = async ({ event, resolve }) => { - event.locals.pb = createInstance(); - const cookie = event.request.headers.get('cookie') || ''; - event.locals.pb.authStore.loadFromCookie(cookie); - event.locals.pb.autoCancellation(false); + event.locals.pb = createInstance(); + const cookie = event.request.headers.get("cookie") || ""; + event.locals.pb.authStore.loadFromCookie(cookie); - try { - if (event.locals.pb.authStore.isValid) { - await event.locals.pb.collection('users').authRefresh(); - event.locals.user = event.locals.pb.authStore.model; - } else { - console.log('Auth not valid'); - } - } catch (error) { - console.error('Error refreshing auth:', error); - event.locals.pb.authStore.clear(); - } + try { + if (event.locals.pb.authStore.isValid) { + await event.locals.pb.collection("users").authRefresh(); + event.locals.user = event.locals.pb.authStore.model; + } else { + console.log("Auth not valid"); + } + } catch (error) { + console.error("Error refreshing auth:", error); + event.locals.pb.authStore.clear(); + } - const response = await resolve(event); - const setCookie = event.locals.pb.authStore.exportToCookie({ - sameSite: 'strict', - secure: !dev, - httpOnly: true - }); - response.headers.set('set-cookie', setCookie); + const response = await resolve(event); + const setCookie = event.locals.pb.authStore.exportToCookie({ + sameSite: "strict", + secure: !dev, + httpOnly: true, + }); + response.headers.set("set-cookie", setCookie); - return response; + return response; }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 2b44e54..33cd067 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -194,7 +194,7 @@