Skip to content

Commit

Permalink
add gitub workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Spikeysanju committed Oct 31, 2024
1 parent e734f97 commit d7ecb8b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 28 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -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
51 changes: 25 additions & 26 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 1 addition & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
<form action="?/logout" method="POST" use:enhance>
<button
type="submit"
class="inline-flex items-center gap-2 rounded-full bg-white/50 px-4 py-2 text-sm font-medium text-gray-600 shadow-sm transition-colors hover:bg-gray-100 dark:bg-gray-800/50 dark:text-gray-300 dark:hover:bg-gray-700/50"
class="inline-flex items-center gap-2 rounded-full bg-white/50 px-4 py-2 text-sm font-medium text-gray-600 shadow-sm transition-colors hover:bg-gray-100 dark:bg-gray-800/50 dark:text-gray-300 dark:hover:bg-gray-700/50 border border-gray-200 dark:border-gray-700"
>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down
2 changes: 1 addition & 1 deletion src/routes/login/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { PageServerLoad } from "./$types";

export const load = (async ({ locals }) => {
if (locals.pb.authStore.isValid) {
throw redirect(302, "/crm");
throw redirect(302, "/");
}
return {};
}) satisfies PageServerLoad;
Expand Down

0 comments on commit d7ecb8b

Please sign in to comment.