Block a user
@cyrmex/auth (0.1.3)
Published 2026-07-31 10:40:54 +00:00 by fdebef
Installation
@cyrmex:registry=https://gitea.cyrmex.cz/api/packages/fdebef/npm/npm install @cyrmex/auth@0.1.3"@cyrmex/auth": "0.1.3"About this package
Sdílená SSO integrace (auth.cyrmex.cz) pro Cyrmex SvelteKit aplikace
@cyrmex/auth
SSO integrace na auth.cyrmex.cz pro Cyrmex SvelteKit aplikace. Distribuce přes Gitea npm registry (stejný model jako @cyrmex/datagrid, viz KB webapp/shared-packages.txt).
Integrace do appky
.env appky:
AUTH_URL=https://auth.cyrmex.cz
AUTH_APP_SLUG=farmis-tools
AUTH_APP_SECRET=... # apps.shared_secret z auth DB
AUTH_DB_HOST=shared-postgres
AUTH_DB_PASSWORD=... # role auth_validator
src/lib/server/sso.ts (jedno místo s konfigem):
import { createAuthApi, type AuthConfig } from '@cyrmex/auth';
export const authConfig: AuthConfig = {
slug: process.env.AUTH_APP_SLUG!,
secret: process.env.AUTH_APP_SECRET!,
authUrl: process.env.AUTH_URL!,
validatorDb: {
host: process.env.AUTH_DB_HOST!,
password: process.env.AUTH_DB_PASSWORD!
},
publicPaths: ['/accept-invite', '/forgot-password', '/reset-password', '/api/health']
};
export const authApi = createAuthApi(authConfig);
hooks.server.ts:
import { sequence } from '@sveltejs/kit/hooks';
import { createAuthHandle } from '@cyrmex/auth';
import { authConfig } from '$lib/server/sso';
const ssoHandle = createAuthHandle(authConfig);
const appHandle = async ({ event, resolve }) => {
// event.locals.ssoUser → find-or-create lokálního profilu, permissions, …
return resolve(event);
};
export const handle = sequence(ssoHandle, appHandle);
src/routes/auth/callback/+server.ts:
import { createCallbackHandler } from '@cyrmex/auth';
import { authConfig } from '$lib/server/sso';
export const GET = createCallbackHandler(authConfig, {
onUser: async (user) => {
// find-or-create lokálního usera podle e-mailu, nastavit auth_user_id
}
});
app.d.ts — do App.Locals přidat:
ssoUser?: import('@cyrmex/auth').SsoUser;
ssoSessionId?: string;
Publish
npm run build
npm publish # registry + scope je v publishConfig; vyžaduje write token
git tag vX.Y.Z && git push --tags
Verzi drž synchronně v gitu a registry (viz KB — osiřelé verze).
Dependencies
Dependencies
| ID | Version |
|---|---|
| pg | ^8.11.3 |
Development Dependencies
| ID | Version |
|---|---|
| @sveltejs/kit | ^2.48.4 |
| @sveltejs/package | ^2.5.8 |
| @sveltejs/vite-plugin-svelte | ^7.0.0 |
| @types/pg | ^8.10.9 |
| svelte | ^5.0.0 |
| svelte-check | ^4.0.0 |
| typescript | ^6.0.0 |
Peer Dependencies
| ID | Version |
|---|---|
| @sveltejs/kit | ^2.0.0 |
| svelte | ^5.0.0 |