cobras-auth-nuxt 1.0.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.
Files changed (32) hide show
  1. package/README.md +302 -0
  2. package/dist/module.cjs +5 -0
  3. package/dist/module.d.mts +134 -0
  4. package/dist/module.d.ts +134 -0
  5. package/dist/module.json +12 -0
  6. package/dist/module.mjs +112 -0
  7. package/dist/runtime/components/CobrasDevTools.vue +89 -0
  8. package/dist/runtime/composables/useCobrasAuth.d.ts +0 -0
  9. package/dist/runtime/composables/useCobrasAuth.js +99 -0
  10. package/dist/runtime/composables/useCobrasDevTools.d.ts +0 -0
  11. package/dist/runtime/composables/useCobrasDevTools.js +69 -0
  12. package/dist/runtime/composables/useCobrasMode.d.ts +0 -0
  13. package/dist/runtime/composables/useCobrasMode.js +25 -0
  14. package/dist/runtime/middleware/auth.d.ts +0 -0
  15. package/dist/runtime/middleware/auth.js +36 -0
  16. package/dist/runtime/middleware/internal.d.ts +0 -0
  17. package/dist/runtime/middleware/internal.js +19 -0
  18. package/dist/runtime/plugins/auth.client.d.ts +0 -0
  19. package/dist/runtime/plugins/auth.client.js +122 -0
  20. package/dist/runtime/plugins/auth.server.d.ts +0 -0
  21. package/dist/runtime/plugins/auth.server.js +69 -0
  22. package/dist/runtime/server/api/exchange.post.d.ts +0 -0
  23. package/dist/runtime/server/api/exchange.post.js +49 -0
  24. package/dist/runtime/server/api/logout.post.d.ts +0 -0
  25. package/dist/runtime/server/api/logout.post.js +27 -0
  26. package/dist/runtime/server/api/refresh.post.d.ts +0 -0
  27. package/dist/runtime/server/api/refresh.post.js +24 -0
  28. package/dist/runtime/server/api/verify.get.d.ts +0 -0
  29. package/dist/runtime/server/api/verify.get.js +50 -0
  30. package/dist/types.d.mts +7 -0
  31. package/dist/types.d.ts +7 -0
  32. package/package.json +62 -0
@@ -0,0 +1,50 @@
1
+ import { defineEventHandler, getHeader, getCookie, createError } from "h3";
2
+ import { useRuntimeConfig } from "#imports";
3
+ export default defineEventHandler(async (event) => {
4
+ const config = useRuntimeConfig();
5
+ const authServiceUrl = config.public.cobrasAuth.authServiceUrl;
6
+ const sessionCookie = getCookie(event, "cobras_session");
7
+ if (sessionCookie) {
8
+ try {
9
+ const session = JSON.parse(Buffer.from(sessionCookie, "base64").toString());
10
+ if (session.expires_at && new Date(session.expires_at) > /* @__PURE__ */ new Date()) {
11
+ return {
12
+ valid: true,
13
+ user: session.user
14
+ };
15
+ }
16
+ } catch {
17
+ }
18
+ }
19
+ const token = getCookie(event, "access_token");
20
+ const cookieHeader = getHeader(event, "cookie") || "";
21
+ if (!token && !cookieHeader.includes("access_token")) {
22
+ throw createError({
23
+ statusCode: 401,
24
+ message: "Not authenticated"
25
+ });
26
+ }
27
+ try {
28
+ const response = await $fetch(
29
+ `${authServiceUrl}/api/auth/verify`,
30
+ {
31
+ headers: {
32
+ cookie: cookieHeader,
33
+ ...token ? { authorization: `Bearer ${token}` } : {}
34
+ }
35
+ }
36
+ );
37
+ return response;
38
+ } catch (error) {
39
+ if (error.statusCode === 401) {
40
+ throw createError({
41
+ statusCode: 401,
42
+ message: "Not authenticated"
43
+ });
44
+ }
45
+ throw createError({
46
+ statusCode: error.statusCode || 500,
47
+ message: error.message || "Auth verification failed"
48
+ });
49
+ }
50
+ });
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.js'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.js'
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module'
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "cobras-auth-nuxt",
3
+ "version": "1.0.0",
4
+ "description": "Nuxt 3/4 module for Cobras Auth service - supports internal (SSO) and public modes",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/Cobras-Solutions/cobras-auth-nuxt"
8
+ },
9
+ "license": "MIT",
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/types.d.ts",
14
+ "import": "./dist/module.mjs",
15
+ "require": "./dist/module.cjs"
16
+ }
17
+ },
18
+ "main": "./dist/module.cjs",
19
+ "module": "./dist/module.mjs",
20
+ "types": "./dist/types.d.ts",
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "nuxt-module-build build",
26
+ "dev": "nuxi dev playground",
27
+ "dev:build": "nuxi build playground",
28
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
29
+ "release": "npm run build && npm publish --access public",
30
+ "lint": "eslint .",
31
+ "test": "vitest run",
32
+ "test:watch": "vitest watch"
33
+ },
34
+ "dependencies": {
35
+ "@nuxt/kit": "^3.14.0",
36
+ "defu": "^6.1.4"
37
+ },
38
+ "devDependencies": {
39
+ "@nuxt/devtools": "^1.6.0",
40
+ "@nuxt/eslint-config": "^0.6.0",
41
+ "@nuxt/module-builder": "^0.8.4",
42
+ "@nuxt/schema": "^3.14.0",
43
+ "@nuxt/test-utils": "^3.14.0",
44
+ "@types/node": "^22.0.0",
45
+ "eslint": "^9.0.0",
46
+ "nuxt": "^3.14.0",
47
+ "typescript": "^5.6.0",
48
+ "vitest": "^2.0.0",
49
+ "vue": "^3.5.0"
50
+ },
51
+ "peerDependencies": {
52
+ "nuxt": "^3.0.0 || ^4.0.0"
53
+ },
54
+ "keywords": [
55
+ "nuxt",
56
+ "nuxt-module",
57
+ "authentication",
58
+ "sso",
59
+ "cobras",
60
+ "auth"
61
+ ]
62
+ }