Compare commits

...

1 Commits

Author SHA1 Message Date
Claude
c4ed7f0735 feat: extract auth types and constants to @comfyorg/auth package
Create a new monorepo package to consolidate authentication logic:
- Add @comfyorg/auth package with types and constants
- Extract AuthHeader, ApiKeyAuthHeader, AuthUserInfo types
- Extract WORKSPACE_STORAGE_KEYS and TOKEN_REFRESH_BUFFER_MS constants
- Re-export from original locations for backward compatibility

This is the first step toward consolidating auth logic into a dedicated
package to improve maintainability and prevent regressions in auth flows.

https://claude.ai/code/session_01PPtA7r3NLJzkYP1ukTmyPr
2026-02-24 03:01:08 +00:00
10 changed files with 113 additions and 29 deletions

View File

@@ -56,6 +56,7 @@
"@alloc/quick-lru": "catalog:",
"@atlaskit/pragmatic-drag-and-drop": "^1.3.1",
"@comfyorg/comfyui-electron-types": "catalog:",
"@comfyorg/auth": "workspace:*",
"@comfyorg/design-system": "workspace:*",
"@comfyorg/registry-types": "workspace:*",
"@comfyorg/shared-frontend-utils": "workspace:*",

View File

@@ -0,0 +1,24 @@
{
"name": "@comfyorg/auth",
"version": "1.0.0",
"private": true,
"description": "Authentication package for ComfyUI Frontend",
"type": "module",
"exports": {
"./types": "./src/types/index.ts",
"./constants": "./src/constants/index.ts"
},
"scripts": {
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"typescript": "catalog:"
},
"packageManager": "pnpm@10.17.1",
"nx": {
"tags": [
"scope:shared",
"type:auth"
]
}
}

View File

@@ -0,0 +1,21 @@
/**
* Storage keys used for workspace authentication state.
*/
export const WORKSPACE_STORAGE_KEYS = {
// sessionStorage keys (cleared on browser close)
CURRENT_WORKSPACE: 'Comfy.Workspace.Current',
TOKEN: 'Comfy.Workspace.Token',
EXPIRES_AT: 'Comfy.Workspace.ExpiresAt',
// localStorage key (persists across browser sessions)
LAST_WORKSPACE_ID: 'Comfy.Workspace.LastWorkspaceId'
} as const
/**
* Buffer time before token expiry to trigger a refresh (5 minutes).
*/
export const TOKEN_REFRESH_BUFFER_MS = 5 * 60 * 1000
/**
* Storage key for API key authentication.
*/
export const API_KEY_STORAGE_KEY = 'comfy_api_key'

View File

@@ -0,0 +1,23 @@
type LoggedInAuthHeader = {
Authorization: `Bearer ${string}`
}
export type ApiKeyAuthHeader = {
'X-API-KEY': string
}
export type AuthHeader = LoggedInAuthHeader | ApiKeyAuthHeader
export interface AuthUserInfo {
id: string
}
/**
* Represents a workspace with the user's role in it.
*/
export interface WorkspaceWithRole {
id: string
name: string
type: 'personal' | 'team'
role: 'owner' | 'member'
}

View File

@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"paths": {
"@/*": ["../../src/*"],
"@comfyorg/auth/*": ["./src/*"]
}
},
"include": ["src/**/*"]
}

File diff suppressed because one or more lines are too long

9
pnpm-lock.yaml generated
View File

@@ -368,6 +368,9 @@ importers:
'@atlaskit/pragmatic-drag-and-drop':
specifier: ^1.3.1
version: 1.3.1
'@comfyorg/auth':
specifier: workspace:*
version: link:packages/auth
'@comfyorg/comfyui-electron-types':
specifier: 'catalog:'
version: 0.6.2
@@ -836,6 +839,12 @@ importers:
specifier: 'catalog:'
version: 3.2.5(typescript@5.9.3)
packages/auth:
devDependencies:
typescript:
specifier: 'catalog:'
version: 5.9.3
packages/design-system:
dependencies:
'@iconify-json/lucide':

View File

@@ -1,10 +1,8 @@
export const WORKSPACE_STORAGE_KEYS = {
// sessionStorage keys (cleared on browser close)
CURRENT_WORKSPACE: 'Comfy.Workspace.Current',
TOKEN: 'Comfy.Workspace.Token',
EXPIRES_AT: 'Comfy.Workspace.ExpiresAt',
// localStorage key (persists across browser sessions)
LAST_WORKSPACE_ID: 'Comfy.Workspace.LastWorkspaceId'
} as const
export const TOKEN_REFRESH_BUFFER_MS = 5 * 60 * 1000
/**
* Re-export workspace constants from the @comfyorg/auth package.
* This file is kept for backward compatibility with existing imports.
*/
export {
TOKEN_REFRESH_BUFFER_MS,
WORKSPACE_STORAGE_KEYS
} from '@comfyorg/auth/constants'

View File

@@ -1,6 +1,5 @@
export interface WorkspaceWithRole {
id: string
name: string
type: 'personal' | 'team'
role: 'owner' | 'member'
}
/**
* Re-export workspace types from the @comfyorg/auth package.
* This file is kept for backward compatibility with existing imports.
*/
export type { WorkspaceWithRole } from '@comfyorg/auth/types'

View File

@@ -1,13 +1,9 @@
type LoggedInAuthHeader = {
Authorization: `Bearer ${string}`
}
export type ApiKeyAuthHeader = {
'X-API-KEY': string
}
export type AuthHeader = LoggedInAuthHeader | ApiKeyAuthHeader
export interface AuthUserInfo {
id: string
}
/**
* Re-export auth types from the @comfyorg/auth package.
* This file is kept for backward compatibility with existing imports.
*/
export type {
ApiKeyAuthHeader,
AuthHeader,
AuthUserInfo
} from '@comfyorg/auth/types'