@zvonimirsun/iszy-nuxt-auth-layer 0.2.4 → 0.2.5

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 CHANGED
@@ -1,73 +1,36 @@
1
1
  # ISZY Nuxt 认证 Layer
2
2
 
3
- 用于 ISZY Nuxt 应用的共享认证 layer,抽取前端 BFF、Redis session、登录登出、认证检查和 OAuth 回调等通用能力。
3
+ [![Nuxt 4.x](https://img.shields.io/badge/Nuxt-4.x-brightgreen)](https://nuxt.com/) [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/ZvonimirSun/iszy-nuxt-auth-layer)
4
+
5
+ 用于 ISZY Nuxt 应用的共享认证 layer,抽取前端 BFF、Redis session、登录登出、登录态检查、OAuth 回调和 SSO 账户完成等通用能力。
4
6
 
5
7
  ## 功能
6
8
 
7
9
  - 基于 Redis 的 httpOnly session cookie。
8
- - session 轮换与短 TTL tombstone,降低并发刷新 token 时的竞态影响。
9
- - 后端 API 代理工具,自动注入 access token,并在 401 时尝试 refresh token。
10
- - 本地登录、登出、登录态检查和 OAuth 回调路由。
11
- - SSO 首次登录账户完成流程:可验证并绑定已有账户,或创建并绑定新账户。
12
- - 通用用户 store、公开用户类型和用户信息裁剪工具。
10
+ - 后端 API 代理与 token 刷新。
11
+ - 本地登录、登出、登录态检查、OAuth 和 SSO 流程。
12
+ - 通用用户 store、公开认证类型和用户信息裁剪工具。
13
13
 
14
14
  ## 使用方式
15
15
 
16
- 安装依赖:
17
-
18
16
  ```bash
19
17
  pnpm add @zvonimirsun/iszy-nuxt-auth-layer
20
18
  ```
21
19
 
22
- 在 Nuxt 应用中继承该 layer:
23
-
24
20
  ```ts
25
21
  export default defineNuxtConfig({
26
22
  extends: ['@zvonimirsun/iszy-nuxt-auth-layer'],
27
- })
28
- ```
29
-
30
- 消费方应用需要按部署环境配置 `runtimeConfig.public.apiOrigin`、Redis 连接信息和 session cookie 选项。
31
-
32
- ## 运行时配置
33
-
34
- ```ts
35
- export default defineNuxtConfig({
36
23
  runtimeConfig: {
24
+ apiOrigin: '',
37
25
  public: {
38
26
  apiOrigin: '',
39
- title: '',
40
- features: {
41
- publicRegister: false,
42
- },
43
- },
44
- redis: {
45
- host: '',
46
- port: 6379,
47
- password: undefined,
48
- },
49
- session: {
50
- cookieName: 'NUXT_SESSION_ID',
51
- maxAge: '7d',
52
- domain: '',
53
27
  },
54
28
  },
55
29
  })
56
30
  ```
57
31
 
58
- ## 应用差异
59
-
60
- 该 layer 只提供通用认证链路,不接管具体应用的业务权限:
61
-
62
- - `iszy-admin` 仍应在消费方保留 admin/superadmin 鉴权和 403 页面语义。
63
- - `iszy-tools-next` 仍应在消费方保留工具权限、工具目录刷新和设置页展示逻辑。
64
-
65
- ## SSO 首次登录
32
+ 消费方应用需要按部署环境配置 API origin、Redis 连接信息和 session cookie 选项。服务端请求优先使用私有的 `apiOrigin`,未配置时回退到 `public.apiOrigin`;OAuth 浏览器跳转和客户端直连仍使用公开地址。
66
33
 
67
- 当 SSO subject 尚未关联本地用户时,回调不会直接创建账户,而是进入短期的账户完成流程:
34
+ ## 文档
68
35
 
69
- - 选择“绑定已有账户”时,通过用户名或 SSO 建议邮箱及密码验证本地账户,验证成功后绑定 SSO。
70
- - 选择“创建新账户”时,可以使用 SSO 建议的用户名、昵称和邮箱创建账户,并同时绑定 SSO。
71
- - SSO 创建的账户始终为启用状态,不受 `publicRegister` 配置影响。
72
- - 待完成凭证只保存在服务端 Redis 中;浏览器只持有独立的 opaque flow ID 与对应的 httpOnly 流程 cookie,多个并发登录流程不会相互覆盖。
73
- - 当前流程不包含邮箱验证码、邀请码或头像同步。
36
+ 详细架构、运行时配置和接入说明请查看 [DeepWiki](https://deepwiki.com/ZvonimirSun/iszy-nuxt-auth-layer)。
package/nuxt.config.ts CHANGED
@@ -22,6 +22,7 @@ export default defineNuxtConfig({
22
22
  },
23
23
  compatibilityDate: '2026-06-30',
24
24
  runtimeConfig: {
25
+ apiOrigin: '',
25
26
  public: {
26
27
  title: '',
27
28
  apiOrigin: '',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zvonimirsun/iszy-nuxt-auth-layer",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "ISZY Nuxt 应用共享认证 layer。",
@@ -7,7 +7,7 @@ import { getProxyRequestHeaders } from 'h3'
7
7
 
8
8
  export async function proxyFetch(event: H3Event) {
9
9
  const sessionId = getSessionId(event)
10
- const { apiOrigin } = usePublicConfig()
10
+ const apiOrigin = useApiOrigin()
11
11
  const target = apiOrigin + event.path.slice(4)
12
12
 
13
13
  const headers = _getForwardRequestHeaders(event)
@@ -51,7 +51,7 @@ export function authFetch(event: H3Event): Fetcher {
51
51
 
52
52
  function createAuthFetch(event: H3Event): Fetcher {
53
53
  const sessionId = getSessionId(event)
54
- const { apiOrigin } = usePublicConfig()
54
+ const apiOrigin = useApiOrigin()
55
55
  const baseFetch = $fetch as (request: unknown, options?: Record<string, unknown>) => Promise<unknown>
56
56
 
57
57
  const authFetcher = async (url: unknown, opts: Record<string, unknown> = {}) => {
@@ -96,7 +96,7 @@ async function _refreshToken(event: H3Event): Promise<SessionData> {
96
96
  throw new Error('REFRESH_FAILED')
97
97
  }
98
98
 
99
- const { apiOrigin } = usePublicConfig()
99
+ const apiOrigin = useApiOrigin()
100
100
  const res = await $fetch<ResultDto<{
101
101
  access_token: string
102
102
  refresh_token: string
@@ -0,0 +1,4 @@
1
+ export function useApiOrigin() {
2
+ const config = useRuntimeConfig()
3
+ return config.apiOrigin || config.public.apiOrigin
4
+ }