@altafusion/fugue-access-gate 0.0.0-stage → 0.9.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 +97 -0
- package/DESIGN.md +67 -0
- package/LICENSE +21 -0
- package/README.md +113 -2
- package/app/middleware/auth.global.ts +29 -0
- package/app/pages/login.vue +38 -0
- package/components/SimpleAuthBrandLogo.vue +26 -0
- package/components/SimpleAuthLoginForm.vue +176 -0
- package/composables/useAppBrand.ts +23 -0
- package/composables/useSimpleAuthLogin.ts +59 -0
- package/composables/useSimpleAuthSession.ts +19 -0
- package/composables/useSimpleAuthSignOut.ts +21 -0
- package/eslint.config.mjs +6 -0
- package/lib/env.ts +61 -0
- package/lib/login.ts +67 -0
- package/lib/path-gate.ts +48 -0
- package/lib/session.ts +32 -0
- package/modules/simple-auth.ts +237 -0
- package/nuxt.config.ts +42 -0
- package/package.json +57 -3
- package/server/api/auth/login.post.ts +22 -0
- package/server/api/auth/logout.post.ts +6 -0
- package/server/api/auth/session.get.ts +12 -0
- package/server/middleware/auth.ts +25 -0
- package/server/utils/access-key.ts +12 -0
- package/server/utils/config.ts +5 -0
- package/server/utils/session.ts +29 -0
- package/types/app-brand.ts +22 -0
- package/types/config.ts +34 -0
- package/types/nuxt-fugue-simple-auth.d.ts +24 -0
|
@@ -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
|
+
}
|
package/types/config.ts
ADDED
|
@@ -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 {}
|