@altafusion/fugue-access-gate 0.0.0-stage → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ import type { H3Event } from 'h3'
2
+ import process from 'node:process'
3
+ import { createSessionToken, verifySessionToken } from '#simple-auth/lib/session'
4
+ import { getSimpleAuthConfig } from './config'
5
+
6
+ export function isAuthenticated(event: H3Event, accessKey: string): boolean {
7
+ const { cookieName, sessionLabel } = getSimpleAuthConfig()
8
+ const token = getCookie(event, cookieName)
9
+ if (!token)
10
+ return false
11
+
12
+ return verifySessionToken(token, accessKey, sessionLabel)
13
+ }
14
+
15
+ export function setSessionCookie(event: H3Event, accessKey: string) {
16
+ const { cookieName, sessionLabel } = getSimpleAuthConfig()
17
+ setCookie(event, cookieName, createSessionToken(accessKey, sessionLabel), {
18
+ httpOnly: true,
19
+ secure: process.env.NODE_ENV === 'production',
20
+ sameSite: 'lax',
21
+ maxAge: 60 * 60 * 24 * 30,
22
+ path: '/'
23
+ })
24
+ }
25
+
26
+ export function clearSessionCookie(event: H3Event) {
27
+ const { cookieName } = getSimpleAuthConfig()
28
+ deleteCookie(event, cookieName, { path: '/' })
29
+ }
@@ -0,0 +1,22 @@
1
+ export interface AppHeaderConfig {
2
+ title?: string
3
+ showColorMode?: boolean
4
+ }
5
+
6
+ /** Product app branding — set in each app's `app.config.ts`. */
7
+ export interface AppBrandConfig {
8
+ name?: string
9
+ logo?: string
10
+ logoAlt?: string
11
+ /** Extra classes on the logo `<img>` (e.g. `dark:brightness-0 dark:invert`). */
12
+ logoClass?: string
13
+ favicon?: string
14
+ }
15
+
16
+ /** Resolved brand values for login chrome and headers. */
17
+ export interface AppBrand {
18
+ name: string
19
+ logo?: string
20
+ logoAlt: string
21
+ logoClass?: string
22
+ }
@@ -0,0 +1,34 @@
1
+ export type FugueSimpleAuthMode = 'full' | 'routes'
2
+
3
+ export interface FugueSimpleAuthConfig {
4
+ /** Env prefix — e.g. MY_SITE → MY_SITE_ACCESS_KEY */
5
+ envPrefix: string
6
+ cookieName: string
7
+ /** HMAC payload label — unique per app */
8
+ sessionLabel: string
9
+ mode: FugueSimpleAuthMode
10
+ loginPath: string
11
+ apiPrefix: string
12
+ protectedRoutes: string[]
13
+ publicExact: string[]
14
+ publicPrefixes: string[]
15
+ publicPaths: string[]
16
+ loginDescription: string
17
+ /** Set at build time — whether SSR auth preset is active */
18
+ authRequired: boolean
19
+ }
20
+
21
+ export const fugueSimpleAuthDefaults: FugueSimpleAuthConfig = {
22
+ envPrefix: 'APP',
23
+ cookieName: 'fugue-access-gate',
24
+ sessionLabel: 'fugue-access-gateenticated',
25
+ mode: 'full',
26
+ loginPath: '/login',
27
+ apiPrefix: '/api/auth',
28
+ protectedRoutes: [],
29
+ publicExact: ['/favicon.ico', '/favicon.svg'],
30
+ publicPrefixes: ['/_nuxt/', '/__nuxt/'],
31
+ publicPaths: [],
32
+ loginDescription: 'Enter the access key to continue.',
33
+ authRequired: false
34
+ }
@@ -0,0 +1,24 @@
1
+ /// <reference types="nuxt/schema" />
2
+
3
+ import type { AppBrandConfig, AppHeaderConfig } from './app-brand'
4
+ import type { FugueSimpleAuthConfig } from './config'
5
+
6
+ declare module 'nuxt/schema' {
7
+ interface PublicRuntimeConfig {
8
+ fugueSimpleAuth: FugueSimpleAuthConfig
9
+ }
10
+ }
11
+
12
+ declare module '#app' {
13
+ interface AppConfig {
14
+ brand?: AppBrandConfig
15
+ header?: AppHeaderConfig
16
+ }
17
+
18
+ interface AppConfigInput {
19
+ brand?: AppBrandConfig
20
+ header?: AppHeaderConfig
21
+ }
22
+ }
23
+
24
+ export {}