@altafusion/fugue-simple-auth 0.0.0-stage → 0.3.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # @altafusion/fugue-simple-auth
2
+
3
+ ## 0.3.0
4
+
5
+ No changes in this release.
6
+
7
+ ## 0.2.0
8
+
9
+ ### Minor Changes
10
+
11
+ - 7767e60: Rebrand for the public release. In `@altafusion/shell`, `CODERMAR_BRANDS`, `CODERMAR_BRAND_THEME` and `utils/codermarBrandTheme` become `ALTAFUSION_*` and `utils/altafusionBrandTheme`, and the brand cookie key is now `altafusion:brand`. In `@altafusion/msw`, the `codermarMsw*` exports become `altafusionMsw*`. The site settings schema `$id` is now `https://altafusion.com/schemas/site-settings.json`. Package descriptions and docs no longer reference private sites.
12
+
13
+ ## 0.1.1
14
+
15
+ No changes in this release.
package/DESIGN.md ADDED
@@ -0,0 +1,67 @@
1
+ # @altafusion/fugue-simple-auth — design
2
+
3
+ Access-key gate for Nuxt apps: optional soft auth via env var, signed session cookie, SSR-safe Netlify deploy.
4
+
5
+ ## Bucket
6
+
7
+ `packages-fugue/` — cross-app reusable (same tier as `fugue-storage`, `fugue-devtools`).
8
+
9
+ ## UI
10
+
11
+ Registers **`@nuxt/ui`** for the default login form. Does **not** extend **`@altafusion/fugue-theme`** — portable for **docus-site template** (Docus theme) and product apps that already extend **`shell`** (and usually **`fugue-theme`** at the app root for tokens).
12
+
13
+ Not `packages-platform` bucket-only (platform infra) or `packages-consumer` (future `@altafusion/auth` = OAuth/sessions).
14
+
15
+ ## Gate modes
16
+
17
+ | Mode | Use case | Behavior |
18
+ |------|----------|----------|
19
+ | **`full`** | Private docs | All routes gated except login, auth API, assets |
20
+ | **`routes`** | Public landing + secure area (organizer area) | Only `protectedRoutes` gated; `/` stays public |
21
+
22
+ ## Configuration
23
+
24
+ Apps extend the layer and set `runtimeConfig.public.fugueSimpleAuth`:
25
+
26
+ ```ts
27
+ runtimeConfig: {
28
+ public: {
29
+ fugueSimpleAuth: {
30
+ envPrefix: 'MY_SITE',
31
+ cookieName: 'my-site-auth',
32
+ sessionLabel: 'my-site-authenticated',
33
+ mode: 'full',
34
+ loginDescription: 'Enter the access key to view this documentation.',
35
+ },
36
+ },
37
+ },
38
+ ```
39
+
40
+ ### Environment variables (per app)
41
+
42
+ Derived from `envPrefix`:
43
+
44
+ | Variable | Purpose |
45
+ |----------|---------|
46
+ | `{PREFIX}_ACCESS_KEY` | Secret — **Functions** scope on Netlify; never inlined at build |
47
+ | `{PREFIX}_AUTH_ENABLED` | `true` on **Builds** scope to enable SSR preset without the secret |
48
+
49
+ ## Security
50
+
51
+ - Access key is read at **runtime** only (`process.env` with dynamic key name).
52
+ - Never assign the key into `runtimeConfig` at build time (Netlify secret scan).
53
+ - Session cookie = HMAC-SHA256 of `sessionLabel` keyed by access key.
54
+
55
+ ## Phasing
56
+
57
+ | Phase | Status |
58
+ |-------|--------|
59
+ | 0–2 | Package + auth engine |
60
+ | 3 | Nuxt layer (middleware, routes, login, build hooks) |
61
+ | 5 | docs-site migration (`full` mode) — done |
62
+ | 6 | landing-site pilot (`routes` mode, `/organizer/**`) — done |
63
+ | 7 | developer-docs page — done |
64
+
65
+ ## Overrides
66
+
67
+ Apps may replace `app/pages/login.vue` for branding. Auth API paths are fixed at `/api/auth/*` for v1.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Altafusion
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,114 @@
1
- # Temporary Holding Version
1
+ # @altafusion/fugue-simple-auth
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Optional **access-key gate** for Nuxt apps: env-driven secret, signed session cookie, SSR-safe Netlify deploy.
4
+
5
+ Design notes: **`DESIGN.md`**.
6
+
7
+ ## UI dependency
8
+
9
+ The default login page uses **Nuxt UI** (`UButton`, `UInput`, `UCard`, …). This layer registers **`@nuxt/ui`** and does **not** extend **`@altafusion/fugue-theme`**.
10
+
11
+ | Context | Who provides `@nuxt/ui` |
12
+ |---------|-------------------------|
13
+ | Doc sites extending **`docus`** (+ optional this layer) | **`docus`** (and this layer — deduped) |
14
+ | Product apps extending **`shell`** / **`fugue-ui`** | **`fugue-nuxt-ui`** (often plus **`fugue-theme`** for tokens) |
15
+ | **Standalone** extend of this layer only | Add **`@nuxt/ui`** to the app or extend a layer that registers it |
16
+
17
+ Override **`app/pages/login.vue`** or slot **`SimpleAuthLoginForm`** for custom branding without pulling Altafusion theme CSS.
18
+
19
+ ## Quick start
20
+
21
+ ```ts
22
+ // apps/my-app/nuxt.config.ts
23
+ export default defineNuxtConfig({
24
+ extends: ['@altafusion/fugue-simple-auth'],
25
+ runtimeConfig: {
26
+ public: {
27
+ fugueSimpleAuth: {
28
+ envPrefix: 'MY_APP',
29
+ cookieName: 'my-app-auth',
30
+ sessionLabel: 'my-app-authenticated',
31
+ mode: 'full',
32
+ loginDescription: 'Enter the access key to continue.',
33
+ },
34
+ },
35
+ },
36
+ })
37
+ ```
38
+
39
+ ```bash
40
+ # .env
41
+ MY_APP_ACCESS_KEY=your-secret-key
42
+ ```
43
+
44
+ ## Configuration
45
+
46
+ | Option | Default | Description |
47
+ |--------|---------|-------------|
48
+ | `envPrefix` | `APP` | Env var prefix → `{PREFIX}_ACCESS_KEY`, `{PREFIX}_AUTH_ENABLED` |
49
+ | `cookieName` | `fugue-simple-auth` | HttpOnly session cookie name |
50
+ | `sessionLabel` | `fugue-simple-authenticated` | HMAC payload — unique per app |
51
+ | `mode` | `full` | `full` (whole site) or `routes` (only `protectedRoutes`) |
52
+ | `loginPath` | `/login` | Login page route |
53
+ | `apiPrefix` | `/api/auth` | Auth API base path |
54
+ | `protectedRoutes` | `[]` | Used in `routes` mode (e.g. `['/team/**']`) |
55
+ | `loginDescription` | generic copy | Subtitle on the default login page |
56
+
57
+ ## Environment variables
58
+
59
+ From `envPrefix` (e.g. `MY_SITE`):
60
+
61
+ | Variable | Purpose |
62
+ |----------|---------|
63
+ | `{PREFIX}_ACCESS_KEY` | Secret — runtime only; never inlined at build |
64
+ | `{PREFIX}_AUTH_ENABLED` | `true` on Netlify **Builds** to enable SSR preset without the secret |
65
+
66
+ ## Gate modes
67
+
68
+ | Mode | Behavior |
69
+ |------|----------|
70
+ | `full` | Gate all routes except login, auth API, assets |
71
+ | `routes` | Public site; only `protectedRoutes` gated (e.g. `/organizer/**`) |
72
+
73
+ ## Netlify (quick)
74
+
75
+ When `{PREFIX}_AUTH_ENABLED=true` **or** `{PREFIX}_ACCESS_KEY` is set at **build** time, the layer automatically:
76
+
77
+ - Sets Nitro preset to **`netlify`** (SSR)
78
+ - Sets **`experimental.externalVue: false`** and merges **`vue`** / **`@vue/server-renderer`** into Nitro **`externals.inline`** (avoids missing `vue/server-renderer` on Netlify — [nuxt#30224](https://github.com/nuxt/nuxt/issues/30224))
79
+ - Prerenders **`/login`**
80
+ - Writes SSR **`_redirects`** (`/* → /.netlify/functions/server`)
81
+
82
+ **Recommended env split** (keeps the secret off the build image):
83
+
84
+ | Variable | Scope | Value |
85
+ |----------|--------|--------|
86
+ | `{PREFIX}_AUTH_ENABLED` | **Builds** | `true` |
87
+ | `{PREFIX}_ACCESS_KEY` | **Functions** | your secret |
88
+
89
+ **Monorepo:** each app still needs its own `netlify.toml`, publish path, and (for SSR) correct **Package directory** in the Netlify UI.
90
+
91
+ **Secret scan:** the access key is never copied into `runtimeConfig` or client bundles — safe to deploy with Netlify’s post-build scanner when env is scoped as above.
92
+
93
+ ## Overrides
94
+
95
+ Replace `app/pages/login.vue` in your app for custom branding, or embed **`SimpleAuthLoginForm`** on a public page.
96
+
97
+ ### Composable and form
98
+
99
+ | Export | Purpose |
100
+ |--------|---------|
101
+ | **`useSimpleAuthLogin()`** | Access key state, submit handler, redirect resolution |
102
+ | **`useSimpleAuthSession()`** | `{ authenticated, required }` from `/api/auth/session` |
103
+ | **`useAppBrand()`** | `{ name, logo, logoAlt }` from `app.config.brand` |
104
+ | **`<SimpleAuthLoginForm>`** | Headless form with `#logo`, `#header`, `#field`, `#error`, `#submit`, `#footer` slots |
105
+
106
+ Props include **`title`**, **`description`**, **`logoSrc`**, **`logoAlt`**, **`logoSize`**, **`logoClass`**, **`redirectTo`**, and button copy. When **`logoSrc`** is unset, the form uses **`app.config.brand.logo`**. **`logoClass`** defaults to **`app.config.brand.logoClass`** (e.g. `dark:brightness-0 dark:invert` for SVGs that use `currentColor`). **`loginDescription`** from config is the default description.
107
+
108
+ Auth API paths are `/api/auth/*` in v1.
109
+
110
+ ## Consumers
111
+
112
+ > **Local — do not copy-sync.** Repo wiring, ports, catalog keys, consuming apps, and docs-site links.
113
+
114
+ - Consuming apps extend this layer either with **`docus`** (`full` mode) or directly (`routes` mode). A public docs site needs no read gate.
@@ -0,0 +1,29 @@
1
+ import type { FugueSimpleAuthConfig } from '#simple-auth/types/config'
2
+ import { shouldGatePath } from '#simple-auth/lib/path-gate'
3
+
4
+ export default defineNuxtRouteMiddleware(async (to) => {
5
+ const config = useRuntimeConfig().public.fugueSimpleAuth as FugueSimpleAuthConfig
6
+ const loginPath = config.loginPath
7
+
8
+ if (to.path === loginPath)
9
+ return
10
+
11
+ // Static export / no access key at build — client gate is inactive (dev still checks live session).
12
+ if (!config.authRequired && !import.meta.dev)
13
+ return
14
+
15
+ // Server requests are gated by server/middleware/auth.ts (cookie-aware).
16
+ if (import.meta.server)
17
+ return
18
+
19
+ if (!shouldGatePath(to.path, config))
20
+ return
21
+
22
+ const { authenticated, required } = await $fetch<{ authenticated: boolean, required: boolean }>(`${config.apiPrefix}/session`)
23
+
24
+ if (!required)
25
+ return
26
+
27
+ if (!authenticated)
28
+ return navigateTo(`${loginPath}?redirect=${encodeURIComponent(to.fullPath)}`)
29
+ })
@@ -0,0 +1,38 @@
1
+ <script setup lang="ts">
2
+ definePageMeta({
3
+ layout: false,
4
+ header: false,
5
+ footer: false,
6
+ })
7
+
8
+ const brand = useAppBrand()
9
+
10
+ useSeoMeta({
11
+ title: 'Sign in',
12
+ robots: 'noindex, nofollow',
13
+ })
14
+ </script>
15
+
16
+ <template>
17
+ <UApp>
18
+ <div class="min-h-dvh flex items-center justify-center bg-default px-4">
19
+ <UCard class="w-full max-w-md">
20
+ <SimpleAuthLoginForm>
21
+ <template #header="{ description }">
22
+ <div class="w-full space-y-1 text-center">
23
+ <h1 class="text-xl font-semibold text-highlighted">
24
+ {{ brand.name }}
25
+ </h1>
26
+ <p
27
+ v-if="description"
28
+ class="text-sm text-muted"
29
+ >
30
+ {{ description }}
31
+ </p>
32
+ </div>
33
+ </template>
34
+ </SimpleAuthLoginForm>
35
+ </UCard>
36
+ </div>
37
+ </UApp>
38
+ </template>
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ const {
3
+ logo,
4
+ alt,
5
+ size = 48,
6
+ logoClass,
7
+ } = defineProps<{
8
+ logo?: string
9
+ alt?: string
10
+ size?: number
11
+ /** Extra classes on the logo `<img>` — from `app.config.brand.logoClass` or per-use override. */
12
+ logoClass?: string
13
+ }>()
14
+ </script>
15
+
16
+ <template>
17
+ <img
18
+ v-if="logo"
19
+ :src="logo"
20
+ :alt="alt"
21
+ :width="size"
22
+ :height="size"
23
+ class="mx-auto shrink-0 rounded-lg object-contain"
24
+ :class="logoClass"
25
+ >
26
+ </template>
@@ -0,0 +1,176 @@
1
+ <script setup lang="ts">
2
+ import type { UseSimpleAuthLoginOptions } from '../composables/useSimpleAuthLogin'
3
+
4
+ const {
5
+ title,
6
+ description,
7
+ submitLabel = 'Continue',
8
+ pendingLabel = 'Checking…',
9
+ placeholder = 'Access key',
10
+ invalidKeyMessage,
11
+ redirectTo,
12
+ logoSrc,
13
+ logoAlt = '',
14
+ logoSize = 48,
15
+ logoClass,
16
+ loginOptions,
17
+ } = defineProps<{
18
+ title?: string
19
+ description?: string
20
+ submitLabel?: string
21
+ pendingLabel?: string
22
+ placeholder?: string
23
+ invalidKeyMessage?: string
24
+ redirectTo?: string
25
+ /** Override `app.config` brand logo when the `#logo` slot is not used. */
26
+ logoSrc?: string
27
+ logoAlt?: string
28
+ logoSize?: number
29
+ /** Override `app.config.brand.logoClass` on the default logo. */
30
+ logoClass?: string
31
+ loginOptions?: Omit<UseSimpleAuthLoginOptions, 'redirectTo' | 'invalidKeyMessage'>
32
+ }>()
33
+
34
+ const brand = useAppBrand()
35
+
36
+ const resolvedLogoSrc = computed(() => logoSrc ?? brand.value.logo)
37
+ const resolvedLogoAlt = computed(() => logoAlt || brand.value.logoAlt)
38
+ const resolvedLogoClass = computed(() => logoClass ?? brand.value.logoClass)
39
+
40
+ const {
41
+ key,
42
+ error,
43
+ pending,
44
+ submit,
45
+ config,
46
+ } = useSimpleAuthLogin({
47
+ redirectTo: () => redirectTo,
48
+ invalidKeyMessage,
49
+ ...loginOptions,
50
+ })
51
+
52
+ const resolvedDescription = computed(
53
+ () => description ?? config.loginDescription,
54
+ )
55
+ </script>
56
+
57
+ <template>
58
+ <form
59
+ class="simple-auth-login-form flex w-full flex-col gap-3 text-center"
60
+ @submit.prevent="submit"
61
+ >
62
+ <slot name="logo">
63
+ <SimpleAuthBrandLogo
64
+ v-if="resolvedLogoSrc"
65
+ class="mb-4"
66
+ :logo="resolvedLogoSrc"
67
+ :alt="resolvedLogoAlt"
68
+ :size="logoSize"
69
+ :logo-class="resolvedLogoClass"
70
+ />
71
+ </slot>
72
+
73
+ <slot
74
+ name="header"
75
+ :title="title"
76
+ :description="resolvedDescription"
77
+ >
78
+ <div
79
+ v-if="title || resolvedDescription"
80
+ class="w-full space-y-1 text-center"
81
+ >
82
+ <h2
83
+ v-if="title"
84
+ class="text-lg font-semibold text-highlighted"
85
+ >
86
+ {{ title }}
87
+ </h2>
88
+ <p
89
+ v-if="resolvedDescription"
90
+ class="text-sm text-muted"
91
+ >
92
+ {{ resolvedDescription }}
93
+ </p>
94
+ </div>
95
+ </slot>
96
+
97
+ <!-- Chrome expects a username field alongside password inputs -->
98
+ <input
99
+ type="text"
100
+ name="username"
101
+ autocomplete="username"
102
+ tabindex="-1"
103
+ aria-hidden="true"
104
+ class="sr-only"
105
+ value="access"
106
+ readonly
107
+ >
108
+
109
+ <div class="simple-auth-login-form__controls mx-auto flex w-full max-w-xs flex-col gap-3">
110
+ <slot
111
+ name="field"
112
+ :model-value="key"
113
+ :update-model-value="(value: string) => { key = value }"
114
+ :pending="pending"
115
+ :placeholder="placeholder"
116
+ >
117
+ <UFormField
118
+ label="Access key"
119
+ name="password"
120
+ required
121
+ class="w-full"
122
+ :ui="{ label: 'justify-center' }"
123
+ >
124
+ <UInput
125
+ v-model="key"
126
+ type="password"
127
+ name="password"
128
+ autocomplete="current-password"
129
+ :placeholder="placeholder"
130
+ size="sm"
131
+ class="w-full"
132
+ autofocus
133
+ required
134
+ :disabled="pending"
135
+ />
136
+ </UFormField>
137
+ </slot>
138
+
139
+ <slot
140
+ v-if="error"
141
+ name="error"
142
+ :message="error"
143
+ >
144
+ <UAlert
145
+ color="error"
146
+ variant="subtle"
147
+ class="w-full text-left"
148
+ :title="error"
149
+ />
150
+ </slot>
151
+
152
+ <slot
153
+ name="submit"
154
+ :pending="pending"
155
+ :disabled="!key || pending"
156
+ :submit-label="submitLabel"
157
+ :pending-label="pendingLabel"
158
+ >
159
+ <UButton
160
+ type="submit"
161
+ size="sm"
162
+ block
163
+ class="w-full"
164
+ :loading="pending"
165
+ :disabled="!key || pending"
166
+ >
167
+ {{ pending ? pendingLabel : submitLabel }}
168
+ </UButton>
169
+ </slot>
170
+ </div>
171
+
172
+ <div class="w-full">
173
+ <slot name="footer" />
174
+ </div>
175
+ </form>
176
+ </template>
@@ -0,0 +1,23 @@
1
+ import type { AppBrand, AppBrandConfig, AppHeaderConfig } from '../types/app-brand'
2
+
3
+ /** Brand from `app.config.brand` with runtime fallbacks (no shell or site-config module required). */
4
+ export function useAppBrand(): ComputedRef<AppBrand> {
5
+ const appConfig = useAppConfig()
6
+ const runtimeAppName = useRuntimeConfig().public.appName as string | undefined
7
+
8
+ return computed(() => {
9
+ const configured = appConfig.brand as AppBrandConfig | undefined
10
+ const header = appConfig.header as AppHeaderConfig | undefined
11
+ const name = configured?.name
12
+ ?? header?.title
13
+ ?? runtimeAppName
14
+ ?? 'App'
15
+
16
+ return {
17
+ name,
18
+ logo: configured?.logo,
19
+ logoAlt: configured?.logoAlt ?? name,
20
+ logoClass: configured?.logoClass
21
+ }
22
+ })
23
+ }
@@ -0,0 +1,59 @@
1
+ import type { MaybeRefOrGetter } from 'vue'
2
+ import type { FugueSimpleAuthConfig } from '../types/config'
3
+ import { resolveSimpleAuthRedirect } from '../lib/login'
4
+
5
+ export interface UseSimpleAuthLoginOptions {
6
+ /** Post-login destination when `?redirect=` is absent. */
7
+ redirectTo?: MaybeRefOrGetter<string | undefined>
8
+ invalidKeyMessage?: string
9
+ onSuccess?: (redirectTo: string) => void | Promise<void>
10
+ }
11
+
12
+ export function useSimpleAuthLogin(options: UseSimpleAuthLoginOptions = {}) {
13
+ const route = useRoute()
14
+ const config = useRuntimeConfig().public.fugueSimpleAuth as FugueSimpleAuthConfig
15
+
16
+ const key = ref('')
17
+ const error = ref('')
18
+ const pending = ref(false)
19
+
20
+ function resolveRedirect(): string {
21
+ const explicit = options.redirectTo !== undefined
22
+ ? toValue(options.redirectTo)
23
+ : undefined
24
+ const fallback = explicit || '/'
25
+ return resolveSimpleAuthRedirect(route.query.redirect, fallback)
26
+ }
27
+
28
+ async function submit() {
29
+ error.value = ''
30
+ pending.value = true
31
+
32
+ try {
33
+ await $fetch(`${config.apiPrefix}/login`, {
34
+ method: 'POST',
35
+ body: { key: key.value }
36
+ })
37
+
38
+ const target = resolveRedirect()
39
+
40
+ if (options.onSuccess)
41
+ await options.onSuccess(target)
42
+ else
43
+ await navigateTo(target)
44
+ } catch {
45
+ error.value = options.invalidKeyMessage ?? 'Invalid access key.'
46
+ } finally {
47
+ pending.value = false
48
+ }
49
+ }
50
+
51
+ return {
52
+ key,
53
+ error,
54
+ pending,
55
+ submit,
56
+ config,
57
+ resolveRedirect
58
+ }
59
+ }
@@ -0,0 +1,19 @@
1
+ import type { SimpleAuthSession } from '../lib/login'
2
+ import type { FugueSimpleAuthConfig } from '../types/config'
3
+
4
+ export function useSimpleAuthSession() {
5
+ const config = useRuntimeConfig().public.fugueSimpleAuth as FugueSimpleAuthConfig
6
+
7
+ // Static export without auth at build time — no /api/auth/* handlers exist.
8
+ // Dev always hits the session API so runtime access-key detection matches the server.
9
+ if (!config.authRequired && !import.meta.dev) {
10
+ return useAsyncData<SimpleAuthSession>(
11
+ 'fugue-simple-auth-session',
12
+ () => Promise.resolve({ authenticated: true, required: false })
13
+ )
14
+ }
15
+
16
+ return useFetch<SimpleAuthSession>(() => `${config.apiPrefix}/session`, {
17
+ key: 'fugue-simple-auth-session'
18
+ })
19
+ }
@@ -0,0 +1,21 @@
1
+ import type { FugueSimpleAuthConfig } from '../types/config'
2
+ import { shouldShowSimpleAuthSignOut } from '../lib/login'
3
+
4
+ export function useSimpleAuthSignOut(options?: { redirectTo?: string }) {
5
+ const { data: session, refresh } = useSimpleAuthSession()
6
+ const redirectTo = options?.redirectTo ?? '/'
7
+
8
+ const showSignOut = computed(() => shouldShowSimpleAuthSignOut(session.value))
9
+
10
+ async function signOut() {
11
+ const config = useRuntimeConfig().public.fugueSimpleAuth as FugueSimpleAuthConfig
12
+ await $fetch(`${config.apiPrefix}/logout`, { method: 'POST' })
13
+ await refresh()
14
+ await navigateTo(redirectTo)
15
+ }
16
+
17
+ return {
18
+ showSignOut,
19
+ signOut
20
+ }
21
+ }
@@ -0,0 +1,6 @@
1
+ // @ts-check
2
+ import { createPackageEslintConfig } from '@altafusion/eslint-config'
3
+
4
+ export default createPackageEslintConfig({
5
+ ignores: ['**/*.md', 'DESIGN.md']
6
+ })
package/lib/env.ts ADDED
@@ -0,0 +1,61 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { join } from 'node:path'
3
+ import process from 'node:process'
4
+
5
+ export function accessKeyEnvName(envPrefix: string): string {
6
+ return [envPrefix, 'ACCESS', 'KEY'].join('_')
7
+ }
8
+
9
+ export function authEnabledEnvName(envPrefix: string): string {
10
+ return [envPrefix, 'AUTH', 'ENABLED'].join('_')
11
+ }
12
+
13
+ export function parseEnvValue(raw: string): string {
14
+ const value = raw.trim()
15
+ const quoted = (value.startsWith('"') && value.endsWith('"'))
16
+ || (value.startsWith('\'') && value.endsWith('\''))
17
+ return quoted
18
+ ? value.slice(1, -1)
19
+ : value
20
+ }
21
+
22
+ export function readEnvFileValue(name: string): string | undefined {
23
+ try {
24
+ const envPath = join(process.cwd(), '.env')
25
+ const line = readFileSync(envPath, 'utf8')
26
+ .split('\n')
27
+ .find(entry => entry.startsWith(`${name}=`))
28
+
29
+ if (!line)
30
+ return undefined
31
+
32
+ return parseEnvValue(line.slice(name.length + 1))
33
+ } catch {
34
+ return undefined
35
+ }
36
+ }
37
+
38
+ /** Build-time only — checks presence, never serializes the secret. */
39
+ export function isAuthEnabledAtBuild(envPrefix: string): boolean {
40
+ const enabledName = authEnabledEnvName(envPrefix)
41
+ const enabled = process.env[enabledName] ?? readEnvFileValue(enabledName)
42
+ if (enabled === 'true')
43
+ return true
44
+
45
+ const keyName = accessKeyEnvName(envPrefix)
46
+ const key = process.env[keyName] ?? readEnvFileValue(keyName)
47
+ return typeof key === 'string' && key.length > 0
48
+ }
49
+
50
+ /** Runtime access key — dynamic env name avoids Nitro inlining (Netlify secret scan). */
51
+ export function readAccessKey(envPrefix: string, devReloadFromDotEnv = false): string {
52
+ const name = accessKeyEnvName(envPrefix)
53
+ const fromFile = devReloadFromDotEnv
54
+ ? readEnvFileValue(name)
55
+ : undefined
56
+ return fromFile ?? process.env[name] ?? ''
57
+ }
58
+
59
+ export function isAccessKeyConfigured(envPrefix: string, devReloadFromDotEnv = false): boolean {
60
+ return Boolean(readAccessKey(envPrefix, devReloadFromDotEnv))
61
+ }