authfyio-nuxt 0.2.1
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/README.md +21 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# authfyio-nuxt
|
|
2
|
+
|
|
3
|
+
Nuxt 3 module for Authfyio — server middleware + auto-imported composables (wraps authfyio-vue).
|
|
4
|
+
|
|
5
|
+
> Part of [Authfyio](https://authfyio.com) — a self-hostable authentication platform.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install authfyio-nuxt
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
See the full guide at **https://authfyio.com/docs**.
|
|
16
|
+
|
|
17
|
+
Point the SDK at your Authfyio instance via the same-origin proxy (`/api/af`) or set `AF_API_BASE_URL` for server-side calls.
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type AuthfyioBackendClientOptions, type SessionClaims } from 'authfyio-backend';
|
|
2
|
+
export type { SessionClaims };
|
|
3
|
+
/**
|
|
4
|
+
* Lightweight Nuxt 3 integration. Drop the server middleware into
|
|
5
|
+
* `server/middleware/authfyio.ts`:
|
|
6
|
+
*
|
|
7
|
+
* import { defineEventHandler } from 'h3';
|
|
8
|
+
* import { authfyioEventHandler } from 'authfyio-nuxt';
|
|
9
|
+
* export default defineEventHandler(authfyioEventHandler({
|
|
10
|
+
* baseUrl: process.env.AF_API_BASE_URL!,
|
|
11
|
+
* }));
|
|
12
|
+
*
|
|
13
|
+
* On the client, use `authfyio-vue` directly (`provideAuthfyio`, `useAuth`,
|
|
14
|
+
* `useUser`). We intentionally don't ship a Nuxt module class here — it adds a
|
|
15
|
+
* hard dependency on the Nuxt Kit — but the tiny plugin below covers 95 % of
|
|
16
|
+
* the integration surface with none of the lock-in.
|
|
17
|
+
*/
|
|
18
|
+
export type NuxtAuthObject = {
|
|
19
|
+
userId: string;
|
|
20
|
+
sessionId: string;
|
|
21
|
+
environmentId: string;
|
|
22
|
+
orgId: string | null;
|
|
23
|
+
orgRole: string | null;
|
|
24
|
+
claims: SessionClaims;
|
|
25
|
+
};
|
|
26
|
+
export declare function authfyioEventHandler(opts: AuthfyioBackendClientOptions): (event: any) => Promise<void>;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,4BAA4B,EACjC,KAAK,aAAa,EACnB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,4BAA4B,IAE9C,OAAO,GAAG,KAAG,OAAO,CAAC,IAAI,CAAC,CAsBlD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AuthfyioBackendClient, } from 'authfyio-backend';
|
|
2
|
+
export function authfyioEventHandler(opts) {
|
|
3
|
+
const client = new AuthfyioBackendClient(opts);
|
|
4
|
+
return async function (event) {
|
|
5
|
+
const cookie = event?.node?.req?.headers?.cookie ??
|
|
6
|
+
(typeof event?.request?.headers?.get === 'function'
|
|
7
|
+
? event.request.headers.get('cookie')
|
|
8
|
+
: null) ??
|
|
9
|
+
'';
|
|
10
|
+
const claims = await client
|
|
11
|
+
.getSessionFromRequest({ headers: { cookie } })
|
|
12
|
+
.catch(() => null);
|
|
13
|
+
event.context = event.context ?? {};
|
|
14
|
+
event.context.authfyio = claims
|
|
15
|
+
? {
|
|
16
|
+
userId: claims.sub,
|
|
17
|
+
sessionId: claims.sid,
|
|
18
|
+
environmentId: claims.env,
|
|
19
|
+
orgId: claims.org ?? null,
|
|
20
|
+
orgRole: claims.org_role ?? null,
|
|
21
|
+
claims,
|
|
22
|
+
}
|
|
23
|
+
: null;
|
|
24
|
+
};
|
|
25
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "authfyio-nuxt",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Nuxt 3 module for Authfyio — server middleware + auto-imported composables (wraps authfyio-vue).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.build.json",
|
|
21
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit",
|
|
22
|
+
"prepublishOnly": "npm run build"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"authfyio-backend": "^0.2.0",
|
|
26
|
+
"authfyio-vue": "^0.2.1",
|
|
27
|
+
"nuxt": ">=3"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"authfyio",
|
|
31
|
+
"auth",
|
|
32
|
+
"nuxt",
|
|
33
|
+
"module"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://authfyio.com/docs",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/authfyio/authfyio.git"
|
|
42
|
+
}
|
|
43
|
+
}
|