feat: add password authentication support (closes #7)

Add token/password auth mode toggle on the login screen.
When password mode is selected, sends { password } instead of
{ token } in the WebSocket connect handshake.

Also adds clipboard utility tests and fixes credential test
to include authMode field.
This commit is contained in:
Nicolas Varrot
2026-02-18 22:07:06 +00:00
parent 16db1cf811
commit 5c47dd2aeb
9 changed files with 745 additions and 21 deletions

582
package-lock.json generated
View File

@@ -32,15 +32,78 @@
"eslint-plugin-react-hooks": "^7.0.1", "eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.5.0", "eslint-plugin-react-refresh": "^0.5.0",
"globals": "^16.5.0", "globals": "^16.5.0",
"jsdom": "^28.1.0",
"typescript": "~5.9.3", "typescript": "~5.9.3",
"typescript-eslint": "^8.55.0", "typescript-eslint": "^8.55.0",
"vite": "^7.3.1", "vite": "^7.3.1",
"vitest": "^4.0.18" "vitest": "^4.0.18"
}, },
"engines": { "engines": {
"node": ">=18" "node": ">=20.19"
} }
}, },
"node_modules/@acemir/cssom": {
"version": "0.9.31",
"resolved": "https://registry.npmjs.org/@acemir/cssom/-/cssom-0.9.31.tgz",
"integrity": "sha512-ZnR3GSaH+/vJ0YlHau21FjfLYjMpYVIzTD8M8vIEQvIGxeOXyXdzCI140rrCY862p/C/BbzWsjc1dgnM9mkoTA==",
"dev": true,
"license": "MIT"
},
"node_modules/@asamuzakjp/css-color": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-4.1.2.tgz",
"integrity": "sha512-NfBUvBaYgKIuq6E/RBLY1m0IohzNHAYyaJGuTK79Z23uNwmz2jl1mPsC5ZxCCxylinKhT1Amn5oNTlx1wN8cQg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@csstools/css-calc": "^3.0.0",
"@csstools/css-color-parser": "^4.0.1",
"@csstools/css-parser-algorithms": "^4.0.0",
"@csstools/css-tokenizer": "^4.0.0",
"lru-cache": "^11.2.5"
}
},
"node_modules/@asamuzakjp/css-color/node_modules/lru-cache": {
"version": "11.2.6",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.2.6.tgz",
"integrity": "sha512-ESL2CrkS/2wTPfuend7Zhkzo2u0daGJ/A2VucJOgQ/C48S/zB8MMeMHSGKYpXhIjbPxfuezITkaBH1wqv00DDQ==",
"dev": true,
"license": "BlueOak-1.0.0",
"engines": {
"node": "20 || >=22"
}
},
"node_modules/@asamuzakjp/dom-selector": {
"version": "6.8.1",
"resolved": "https://registry.npmjs.org/@asamuzakjp/dom-selector/-/dom-selector-6.8.1.tgz",
"integrity": "sha512-MvRz1nCqW0fsy8Qz4dnLIvhOlMzqDVBabZx6lH+YywFDdjXhMY37SmpV1XFX3JzG5GWHn63j6HX6QPr3lZXHvQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@asamuzakjp/nwsapi": "^2.3.9",
"bidi-js": "^1.0.3",
"css-tree": "^3.1.0",
"is-potential-custom-element-name": "^1.0.1",
"lru-cache": "^11.2.6"
}
},
"node_modules/@asamuzakjp/dom-selector/node_modules/lru-cache": {
"version": "11.2.6",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.2.6.tgz",
"integrity": "sha512-ESL2CrkS/2wTPfuend7Zhkzo2u0daGJ/A2VucJOgQ/C48S/zB8MMeMHSGKYpXhIjbPxfuezITkaBH1wqv00DDQ==",
"dev": true,
"license": "BlueOak-1.0.0",
"engines": {
"node": "20 || >=22"
}
},
"node_modules/@asamuzakjp/nwsapi": {
"version": "2.3.9",
"resolved": "https://registry.npmjs.org/@asamuzakjp/nwsapi/-/nwsapi-2.3.9.tgz",
"integrity": "sha512-n8GuYSrI9bF7FFZ/SjhwevlHc8xaVlb/7HmHelnc/PZXBD2ZR49NnN9sMMuDdEGPeeRQ5d0hqlSlEpgCX3Wl0Q==",
"dev": true,
"license": "MIT"
},
"node_modules/@babel/code-frame": { "node_modules/@babel/code-frame": {
"version": "7.29.0", "version": "7.29.0",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.0.tgz", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.0.tgz",
@@ -333,6 +396,151 @@
"node": ">=18" "node": ">=18"
} }
}, },
"node_modules/@bramus/specificity": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/@bramus/specificity/-/specificity-2.4.2.tgz",
"integrity": "sha512-ctxtJ/eA+t+6q2++vj5j7FYX3nRu311q1wfYH3xjlLOsczhlhxAg2FWNUXhpGvAw3BWo1xBcvOV6/YLc2r5FJw==",
"dev": true,
"license": "MIT",
"dependencies": {
"css-tree": "^3.0.0"
},
"bin": {
"specificity": "bin/cli.js"
}
},
"node_modules/@csstools/color-helpers": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-6.0.1.tgz",
"integrity": "sha512-NmXRccUJMk2AWA5A7e5a//3bCIMyOu2hAtdRYrhPPHjDxINuCwX1w6rnIZ4xjLcp0ayv6h8Pc3X0eJUGiAAXHQ==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/csstools"
},
{
"type": "opencollective",
"url": "https://opencollective.com/csstools"
}
],
"license": "MIT-0",
"engines": {
"node": ">=20.19.0"
}
},
"node_modules/@csstools/css-calc": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-3.1.1.tgz",
"integrity": "sha512-HJ26Z/vmsZQqs/o3a6bgKslXGFAungXGbinULZO3eMsOyNJHeBBZfup5FiZInOghgoM4Hwnmw+OgbJCNg1wwUQ==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/csstools"
},
{
"type": "opencollective",
"url": "https://opencollective.com/csstools"
}
],
"license": "MIT",
"engines": {
"node": ">=20.19.0"
},
"peerDependencies": {
"@csstools/css-parser-algorithms": "^4.0.0",
"@csstools/css-tokenizer": "^4.0.0"
}
},
"node_modules/@csstools/css-color-parser": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/@csstools/css-color-parser/-/css-color-parser-4.0.1.tgz",
"integrity": "sha512-vYwO15eRBEkeF6xjAno/KQ61HacNhfQuuU/eGwH67DplL0zD5ZixUa563phQvUelA07yDczIXdtmYojCphKJcw==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/csstools"
},
{
"type": "opencollective",
"url": "https://opencollective.com/csstools"
}
],
"license": "MIT",
"dependencies": {
"@csstools/color-helpers": "^6.0.1",
"@csstools/css-calc": "^3.0.0"
},
"engines": {
"node": ">=20.19.0"
},
"peerDependencies": {
"@csstools/css-parser-algorithms": "^4.0.0",
"@csstools/css-tokenizer": "^4.0.0"
}
},
"node_modules/@csstools/css-parser-algorithms": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-4.0.0.tgz",
"integrity": "sha512-+B87qS7fIG3L5h3qwJ/IFbjoVoOe/bpOdh9hAjXbvx0o8ImEmUsGXN0inFOnk2ChCFgqkkGFQ+TpM5rbhkKe4w==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/csstools"
},
{
"type": "opencollective",
"url": "https://opencollective.com/csstools"
}
],
"license": "MIT",
"engines": {
"node": ">=20.19.0"
},
"peerDependencies": {
"@csstools/css-tokenizer": "^4.0.0"
}
},
"node_modules/@csstools/css-syntax-patches-for-csstree": {
"version": "1.0.27",
"resolved": "https://registry.npmjs.org/@csstools/css-syntax-patches-for-csstree/-/css-syntax-patches-for-csstree-1.0.27.tgz",
"integrity": "sha512-sxP33Jwg1bviSUXAV43cVYdmjt2TLnLXNqCWl9xmxHawWVjGz/kEbdkr7F9pxJNBN2Mh+dq0crgItbW6tQvyow==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/csstools"
},
{
"type": "opencollective",
"url": "https://opencollective.com/csstools"
}
],
"license": "MIT-0"
},
"node_modules/@csstools/css-tokenizer": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-4.0.0.tgz",
"integrity": "sha512-QxULHAm7cNu72w97JUNCBFODFaXpbDg+dP8b/oWFAZ2MTRppA3U00Y2L1HqaS4J6yBqxwa/Y3nMBaxVKbB/NsA==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/csstools"
},
{
"type": "opencollective",
"url": "https://opencollective.com/csstools"
}
],
"license": "MIT",
"engines": {
"node": ">=20.19.0"
}
},
"node_modules/@esbuild/aix-ppc64": { "node_modules/@esbuild/aix-ppc64": {
"version": "0.27.3", "version": "0.27.3",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.3.tgz", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.3.tgz",
@@ -906,6 +1114,24 @@
"node": "^18.18.0 || ^20.9.0 || >=21.1.0" "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
} }
}, },
"node_modules/@exodus/bytes": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/@exodus/bytes/-/bytes-1.14.1.tgz",
"integrity": "sha512-OhkBFWI6GcRMUroChZiopRiSp2iAMvEBK47NhJooDqz1RERO4QuZIZnjP63TXX8GAiLABkYmX+fuQsdJ1dd2QQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
},
"peerDependencies": {
"@noble/hashes": "^1.8.0 || ^2.0.0"
},
"peerDependenciesMeta": {
"@noble/hashes": {
"optional": true
}
}
},
"node_modules/@humanfs/core": { "node_modules/@humanfs/core": {
"version": "0.19.1", "version": "0.19.1",
"resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz",
@@ -2213,6 +2439,16 @@
"acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0"
} }
}, },
"node_modules/agent-base": {
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz",
"integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 14"
}
},
"node_modules/ajv": { "node_modules/ajv": {
"version": "6.12.6", "version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
@@ -2309,6 +2545,16 @@
"baseline-browser-mapping": "dist/cli.js" "baseline-browser-mapping": "dist/cli.js"
} }
}, },
"node_modules/bidi-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/bidi-js/-/bidi-js-1.0.3.tgz",
"integrity": "sha512-RKshQI1R3YQ+n9YJz2QQ147P66ELpa1FQEg20Dk8oW9t2KgLbpDLLp9aGZ7y8WHSshDknG0bknqGw5/tyCs5tw==",
"dev": true,
"license": "MIT",
"dependencies": {
"require-from-string": "^2.0.2"
}
},
"node_modules/brace-expansion": { "node_modules/brace-expansion": {
"version": "1.1.12", "version": "1.1.12",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz",
@@ -2530,12 +2776,66 @@
"node": ">= 8" "node": ">= 8"
} }
}, },
"node_modules/css-tree": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/css-tree/-/css-tree-3.1.0.tgz",
"integrity": "sha512-0eW44TGN5SQXU1mWSkKwFstI/22X2bG1nYzZTYMAWjylYURhse752YgbE4Cx46AC+bAvI+/dYTPRk1LqSUnu6w==",
"dev": true,
"license": "MIT",
"dependencies": {
"mdn-data": "2.12.2",
"source-map-js": "^1.0.1"
},
"engines": {
"node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0"
}
},
"node_modules/cssstyle": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-6.0.1.tgz",
"integrity": "sha512-IoJs7La+oFp/AB033wBStxNOJt4+9hHMxsXUPANcoXL2b3W4DZKghlJ2cI/eyeRZIQ9ysvYEorVhjrcYctWbog==",
"dev": true,
"license": "MIT",
"dependencies": {
"@asamuzakjp/css-color": "^4.1.2",
"@csstools/css-syntax-patches-for-csstree": "^1.0.26",
"css-tree": "^3.1.0",
"lru-cache": "^11.2.5"
},
"engines": {
"node": ">=20"
}
},
"node_modules/cssstyle/node_modules/lru-cache": {
"version": "11.2.6",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.2.6.tgz",
"integrity": "sha512-ESL2CrkS/2wTPfuend7Zhkzo2u0daGJ/A2VucJOgQ/C48S/zB8MMeMHSGKYpXhIjbPxfuezITkaBH1wqv00DDQ==",
"dev": true,
"license": "BlueOak-1.0.0",
"engines": {
"node": "20 || >=22"
}
},
"node_modules/csstype": { "node_modules/csstype": {
"version": "3.2.3", "version": "3.2.3",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz",
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/data-urls": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/data-urls/-/data-urls-7.0.0.tgz",
"integrity": "sha512-23XHcCF+coGYevirZceTVD7NdJOqVn+49IHyxgszm+JIiHLoB2TkmPtsYkNWT1pvRSGkc35L6NHs0yHkN2SumA==",
"dev": true,
"license": "MIT",
"dependencies": {
"whatwg-mimetype": "^5.0.0",
"whatwg-url": "^16.0.0"
},
"engines": {
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
}
},
"node_modules/debug": { "node_modules/debug": {
"version": "4.4.3", "version": "4.4.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
@@ -2553,6 +2853,13 @@
} }
} }
}, },
"node_modules/decimal.js": {
"version": "10.6.0",
"resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz",
"integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==",
"dev": true,
"license": "MIT"
},
"node_modules/decode-named-character-reference": { "node_modules/decode-named-character-reference": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.3.0.tgz", "resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.3.0.tgz",
@@ -2624,6 +2931,19 @@
"node": ">=10.13.0" "node": ">=10.13.0"
} }
}, },
"node_modules/entities": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/entities/-/entities-6.0.1.tgz",
"integrity": "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g==",
"dev": true,
"license": "BSD-2-Clause",
"engines": {
"node": ">=0.12"
},
"funding": {
"url": "https://github.com/fb55/entities?sponsor=1"
}
},
"node_modules/es-module-lexer": { "node_modules/es-module-lexer": {
"version": "1.7.0", "version": "1.7.0",
"resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz",
@@ -3165,6 +3485,19 @@
"node": ">=12.0.0" "node": ">=12.0.0"
} }
}, },
"node_modules/html-encoding-sniffer": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-6.0.0.tgz",
"integrity": "sha512-CV9TW3Y3f8/wT0BRFc1/KAVQ3TUHiXmaAb6VW9vtiMFf7SLoMd1PdAc4W3KFOFETBJUb90KatHqlsZMWV+R9Gg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@exodus/bytes": "^1.6.0"
},
"engines": {
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
}
},
"node_modules/html-escaper": { "node_modules/html-escaper": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz", "resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz",
@@ -3182,6 +3515,34 @@
"url": "https://opencollective.com/unified" "url": "https://opencollective.com/unified"
} }
}, },
"node_modules/http-proxy-agent": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz",
"integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==",
"dev": true,
"license": "MIT",
"dependencies": {
"agent-base": "^7.1.0",
"debug": "^4.3.4"
},
"engines": {
"node": ">= 14"
}
},
"node_modules/https-proxy-agent": {
"version": "7.0.6",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz",
"integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==",
"dev": true,
"license": "MIT",
"dependencies": {
"agent-base": "^7.1.2",
"debug": "4"
},
"engines": {
"node": ">= 14"
}
},
"node_modules/ignore": { "node_modules/ignore": {
"version": "5.3.2", "version": "5.3.2",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
@@ -3304,6 +3665,13 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/is-potential-custom-element-name": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz",
"integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==",
"dev": true,
"license": "MIT"
},
"node_modules/isexe": { "node_modules/isexe": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
@@ -3379,6 +3747,47 @@
"js-yaml": "bin/js-yaml.js" "js-yaml": "bin/js-yaml.js"
} }
}, },
"node_modules/jsdom": {
"version": "28.1.0",
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-28.1.0.tgz",
"integrity": "sha512-0+MoQNYyr2rBHqO1xilltfDjV9G7ymYGlAUazgcDLQaUf8JDHbuGwsxN6U9qWaElZ4w1B2r7yEGIL3GdeW3Rug==",
"dev": true,
"license": "MIT",
"dependencies": {
"@acemir/cssom": "^0.9.31",
"@asamuzakjp/dom-selector": "^6.8.1",
"@bramus/specificity": "^2.4.2",
"@exodus/bytes": "^1.11.0",
"cssstyle": "^6.0.1",
"data-urls": "^7.0.0",
"decimal.js": "^10.6.0",
"html-encoding-sniffer": "^6.0.0",
"http-proxy-agent": "^7.0.2",
"https-proxy-agent": "^7.0.6",
"is-potential-custom-element-name": "^1.0.1",
"parse5": "^8.0.0",
"saxes": "^6.0.0",
"symbol-tree": "^3.2.4",
"tough-cookie": "^6.0.0",
"undici": "^7.21.0",
"w3c-xmlserializer": "^5.0.0",
"webidl-conversions": "^8.0.1",
"whatwg-mimetype": "^5.0.0",
"whatwg-url": "^16.0.0",
"xml-name-validator": "^5.0.0"
},
"engines": {
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
},
"peerDependencies": {
"canvas": "^3.0.0"
},
"peerDependenciesMeta": {
"canvas": {
"optional": true
}
}
},
"node_modules/jsesc": { "node_modules/jsesc": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz",
@@ -4122,6 +4531,13 @@
"url": "https://opencollective.com/unified" "url": "https://opencollective.com/unified"
} }
}, },
"node_modules/mdn-data": {
"version": "2.12.2",
"resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.12.2.tgz",
"integrity": "sha512-IEn+pegP1aManZuckezWCO+XZQDplx1366JoVhTpMpBB1sPey/SbveZQUosKiKiGYjg1wH4pMlNgXbCiYgihQA==",
"dev": true,
"license": "CC0-1.0"
},
"node_modules/micromark": { "node_modules/micromark": {
"version": "4.0.2", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/micromark/-/micromark-4.0.2.tgz", "resolved": "https://registry.npmjs.org/micromark/-/micromark-4.0.2.tgz",
@@ -4835,6 +5251,19 @@
"integrity": "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==", "integrity": "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/parse5": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/parse5/-/parse5-8.0.0.tgz",
"integrity": "sha512-9m4m5GSgXjL4AjumKzq1Fgfp3Z8rsvjRNbnkVwfu2ImRqE5D0LnY2QfDen18FSY9C573YU5XxSapdHZTZ2WolA==",
"dev": true,
"license": "MIT",
"dependencies": {
"entities": "^6.0.0"
},
"funding": {
"url": "https://github.com/inikulin/parse5?sponsor=1"
}
},
"node_modules/path-exists": { "node_modules/path-exists": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
@@ -5094,6 +5523,16 @@
"url": "https://opencollective.com/unified" "url": "https://opencollective.com/unified"
} }
}, },
"node_modules/require-from-string": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/resolve-from": { "node_modules/resolve-from": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
@@ -5148,6 +5587,19 @@
"fsevents": "~2.3.2" "fsevents": "~2.3.2"
} }
}, },
"node_modules/saxes": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz",
"integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==",
"dev": true,
"license": "ISC",
"dependencies": {
"xmlchars": "^2.2.0"
},
"engines": {
"node": ">=v12.22.7"
}
},
"node_modules/scheduler": { "node_modules/scheduler": {
"version": "0.27.0", "version": "0.27.0",
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz",
@@ -5285,6 +5737,13 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/symbol-tree": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
"integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==",
"dev": true,
"license": "MIT"
},
"node_modules/tailwind-merge": { "node_modules/tailwind-merge": {
"version": "3.4.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.4.0.tgz", "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.4.0.tgz",
@@ -5357,6 +5816,52 @@
"node": ">=14.0.0" "node": ">=14.0.0"
} }
}, },
"node_modules/tldts": {
"version": "7.0.23",
"resolved": "https://registry.npmjs.org/tldts/-/tldts-7.0.23.tgz",
"integrity": "sha512-ASdhgQIBSay0R/eXggAkQ53G4nTJqTXqC2kbaBbdDwM7SkjyZyO0OaaN1/FH7U/yCeqOHDwFO5j8+Os/IS1dXw==",
"dev": true,
"license": "MIT",
"dependencies": {
"tldts-core": "^7.0.23"
},
"bin": {
"tldts": "bin/cli.js"
}
},
"node_modules/tldts-core": {
"version": "7.0.23",
"resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-7.0.23.tgz",
"integrity": "sha512-0g9vrtDQLrNIiCj22HSe9d4mLVG3g5ph5DZ8zCKBr4OtrspmNB6ss7hVyzArAeE88ceZocIEGkyW1Ime7fxPtQ==",
"dev": true,
"license": "MIT"
},
"node_modules/tough-cookie": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-6.0.0.tgz",
"integrity": "sha512-kXuRi1mtaKMrsLUxz3sQYvVl37B0Ns6MzfrtV5DvJceE9bPyspOqk9xxv7XbZWcfLWbFmm997vl83qUWVJA64w==",
"dev": true,
"license": "BSD-3-Clause",
"dependencies": {
"tldts": "^7.0.5"
},
"engines": {
"node": ">=16"
}
},
"node_modules/tr46": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-6.0.0.tgz",
"integrity": "sha512-bLVMLPtstlZ4iMQHpFHTR7GAGj2jxi8Dg0s2h2MafAE4uSWF98FC/3MomU51iQAMf8/qDUbKWf5GxuvvVcXEhw==",
"dev": true,
"license": "MIT",
"dependencies": {
"punycode": "^2.3.1"
},
"engines": {
"node": ">=20"
}
},
"node_modules/trim-lines": { "node_modules/trim-lines": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz",
@@ -5441,6 +5946,16 @@
"typescript": ">=4.8.4 <6.0.0" "typescript": ">=4.8.4 <6.0.0"
} }
}, },
"node_modules/undici": {
"version": "7.22.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-7.22.0.tgz",
"integrity": "sha512-RqslV2Us5BrllB+JeiZnK4peryVTndy9Dnqq62S3yYRRTj0tFQCwEniUy2167skdGOy3vqRzEvl1Dm4sV2ReDg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=20.18.1"
}
},
"node_modules/undici-types": { "node_modules/undici-types": {
"version": "7.16.0", "version": "7.16.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
@@ -5770,6 +6285,54 @@
} }
} }
}, },
"node_modules/w3c-xmlserializer": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz",
"integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==",
"dev": true,
"license": "MIT",
"dependencies": {
"xml-name-validator": "^5.0.0"
},
"engines": {
"node": ">=18"
}
},
"node_modules/webidl-conversions": {
"version": "8.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-8.0.1.tgz",
"integrity": "sha512-BMhLD/Sw+GbJC21C/UgyaZX41nPt8bUTg+jWyDeg7e7YN4xOM05YPSIXceACnXVtqyEw/LMClUQMtMZ+PGGpqQ==",
"dev": true,
"license": "BSD-2-Clause",
"engines": {
"node": ">=20"
}
},
"node_modules/whatwg-mimetype": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-5.0.0.tgz",
"integrity": "sha512-sXcNcHOC51uPGF0P/D4NVtrkjSU2fNsm9iog4ZvZJsL3rjoDAzXZhkm2MWt1y+PUdggKAYVoMAIYcs78wJ51Cw==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=20"
}
},
"node_modules/whatwg-url": {
"version": "16.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-16.0.0.tgz",
"integrity": "sha512-9CcxtEKsf53UFwkSUZjG+9vydAsFO4lFHBpJUtjBcoJOCJpKnSJNwCw813zrYJHpCJ7sgfbtOe0V5Ku7Pa1XMQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@exodus/bytes": "^1.11.0",
"tr46": "^6.0.0",
"webidl-conversions": "^8.0.1"
},
"engines": {
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
}
},
"node_modules/which": { "node_modules/which": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
@@ -5813,6 +6376,23 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/xml-name-validator": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz",
"integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==",
"dev": true,
"license": "Apache-2.0",
"engines": {
"node": ">=18"
}
},
"node_modules/xmlchars": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz",
"integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==",
"dev": true,
"license": "MIT"
},
"node_modules/yallist": { "node_modules/yallist": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",

View File

@@ -60,6 +60,7 @@
"eslint-plugin-react-hooks": "^7.0.1", "eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.5.0", "eslint-plugin-react-refresh": "^0.5.0",
"globals": "^16.5.0", "globals": "^16.5.0",
"jsdom": "^28.1.0",
"typescript": "~5.9.3", "typescript": "~5.9.3",
"typescript-eslint": "^8.55.0", "typescript-eslint": "^8.55.0",
"vite": "^7.3.1", "vite": "^7.3.1",

View File

@@ -1,10 +1,10 @@
import { useState } from 'react'; import { useState } from 'react';
import { Sparkles, Eye, EyeOff, Loader2 } from 'lucide-react'; import { Sparkles, Eye, EyeOff, Loader2, Key, Lock } from 'lucide-react';
import { useT } from '../hooks/useLocale'; import { useT } from '../hooks/useLocale';
import { getStoredCredentials } from '../lib/credentials'; import { getStoredCredentials, type AuthMode } from '../lib/credentials';
interface Props { interface Props {
onConnect: (url: string, token: string) => void; onConnect: (url: string, secret: string, authMode: AuthMode) => void;
error?: string | null; error?: string | null;
isConnecting?: boolean; isConnecting?: boolean;
} }
@@ -31,11 +31,17 @@ function getInitialToken(): string {
return stored?.token ?? ''; return stored?.token ?? '';
} }
function getInitialAuthMode(): AuthMode {
const stored = getStoredCredentials();
return stored?.authMode ?? 'token';
}
export function LoginScreen({ onConnect, error, isConnecting }: Props) { export function LoginScreen({ onConnect, error, isConnecting }: Props) {
const t = useT(); const t = useT();
const [url, setUrl] = useState(getInitialUrl); const [url, setUrl] = useState(getInitialUrl);
const [token, setToken] = useState(getInitialToken); const [token, setToken] = useState(getInitialToken);
const [showToken, setShowToken] = useState(false); const [showToken, setShowToken] = useState(false);
const [authMode, setAuthMode] = useState<AuthMode>(getInitialAuthMode);
const urlTrimmed = url.trim(); const urlTrimmed = url.trim();
const isValidWsUrl = /^wss?:\/\/.+/.test(urlTrimmed); const isValidWsUrl = /^wss?:\/\/.+/.test(urlTrimmed);
@@ -44,7 +50,7 @@ export function LoginScreen({ onConnect, error, isConnecting }: Props) {
const handleSubmit = (e: React.FormEvent) => { const handleSubmit = (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
if (!urlTrimmed || !token.trim() || !isValidWsUrl) return; if (!urlTrimmed || !token.trim() || !isValidWsUrl) return;
onConnect(urlTrimmed, token.trim()); onConnect(urlTrimmed, token.trim(), authMode);
}; };
return ( return (
@@ -83,9 +89,39 @@ export function LoginScreen({ onConnect, error, isConnecting }: Props) {
)} )}
</div> </div>
{/* Auth mode toggle */}
<div className="flex gap-2">
<button
type="button"
onClick={() => setAuthMode('token')}
disabled={isConnecting}
className={`flex-1 flex items-center justify-center gap-1.5 rounded-xl border px-3 py-2 text-xs font-medium transition-all ${
authMode === 'token'
? 'border-[var(--pc-accent-dim)] bg-[var(--pc-accent-dim)]/10 text-pc-text'
: 'border-pc-border bg-pc-elevated/30 text-pc-text-muted hover:bg-pc-elevated/50'
}`}
>
<Key size={14} />
{t('login.authToken')}
</button>
<button
type="button"
onClick={() => setAuthMode('password')}
disabled={isConnecting}
className={`flex-1 flex items-center justify-center gap-1.5 rounded-xl border px-3 py-2 text-xs font-medium transition-all ${
authMode === 'password'
? 'border-[var(--pc-accent-dim)] bg-[var(--pc-accent-dim)]/10 text-pc-text'
: 'border-pc-border bg-pc-elevated/30 text-pc-text-muted hover:bg-pc-elevated/50'
}`}
>
<Lock size={14} />
{t('login.authPassword')}
</button>
</div>
<div className="space-y-2"> <div className="space-y-2">
<label htmlFor="gateway-token" className="block text-xs font-medium text-pc-text-secondary uppercase tracking-wider"> <label htmlFor="gateway-token" className="block text-xs font-medium text-pc-text-secondary uppercase tracking-wider">
{t('login.token')} {authMode === 'password' ? t('login.password') : t('login.token')}
</label> </label>
<div className="relative"> <div className="relative">
<input <input
@@ -93,7 +129,7 @@ export function LoginScreen({ onConnect, error, isConnecting }: Props) {
type={showToken ? 'text' : 'password'} type={showToken ? 'text' : 'password'}
value={token} value={token}
onChange={e => setToken(e.target.value)} onChange={e => setToken(e.target.value)}
placeholder={t('login.tokenPlaceholder')} placeholder={authMode === 'password' ? t('login.passwordPlaceholder') : t('login.tokenPlaceholder')}
className="w-full rounded-xl border border-pc-border bg-pc-elevated/50 px-4 py-3 pr-12 text-sm text-pc-text placeholder:text-pc-text-faint outline-none focus:border-[var(--pc-accent-dim)] focus:ring-1 focus:ring-[var(--pc-accent-glow)] transition-all" className="w-full rounded-xl border border-pc-border bg-pc-elevated/50 px-4 py-3 pr-12 text-sm text-pc-text placeholder:text-pc-text-faint outline-none focus:border-[var(--pc-accent-dim)] focus:ring-1 focus:ring-[var(--pc-accent-glow)] transition-all"
autoComplete="current-password" autoComplete="current-password"
disabled={isConnecting} disabled={isConnecting}

View File

@@ -1,7 +1,7 @@
import { useState, useEffect, useRef, useCallback } from 'react'; import { useState, useEffect, useRef, useCallback } from 'react';
import { GatewayClient, type JsonPayload } from '../lib/gateway'; import { GatewayClient, type JsonPayload } from '../lib/gateway';
import { genIdempotencyKey } from '../lib/utils'; import { genIdempotencyKey } from '../lib/utils';
import { getStoredCredentials, storeCredentials, clearCredentials } from '../lib/credentials'; import { getStoredCredentials, storeCredentials, clearCredentials, type AuthMode } from '../lib/credentials';
import { getOrCreateDeviceIdentity } from '../lib/deviceIdentity'; import { getOrCreateDeviceIdentity } from '../lib/deviceIdentity';
import { isSystemEvent } from '../lib/systemEvent'; import { isSystemEvent } from '../lib/systemEvent';
import { getCachedMessages, setCachedMessages, mergeWithCache } from '../lib/messageCache'; import { getCachedMessages, setCachedMessages, mergeWithCache } from '../lib/messageCache';
@@ -272,13 +272,13 @@ export function useGateway() {
} }
}, []); }, []);
const setupClient = useCallback(async (wsUrl: string, token: string) => { const setupClient = useCallback(async (wsUrl: string, token: string, authMode: AuthMode = 'token') => {
// Tear down existing client // Tear down existing client
if (clientRef.current) { if (clientRef.current) {
clientRef.current.disconnect(); clientRef.current.disconnect();
} }
const client = new GatewayClient(wsUrl, token); const client = new GatewayClient(wsUrl, token, authMode);
clientRef.current = client; clientRef.current = client;
// Load device identity for signed connect handshake // Load device identity for signed connect handshake
@@ -296,7 +296,7 @@ export function useGateway() {
setConnectError(null); setConnectError(null);
setIsConnecting(false); setIsConnecting(false);
isConnectingRef.current = false; isConnectingRef.current = false;
storeCredentials(wsUrl, token); storeCredentials(wsUrl, token, authMode);
loadSessions(); loadSessions();
loadAgentIdentity(); loadAgentIdentity();
loadHistory(activeSessionRef.current); loadHistory(activeSessionRef.current);
@@ -445,7 +445,7 @@ export function useGateway() {
const stored = getStoredCredentials(); const stored = getStoredCredentials();
if (stored) { if (stored) {
// Init on mount — setupClient sets state as part of establishing the connection // Init on mount — setupClient sets state as part of establishing the connection
setupClient(stored.url, stored.token); setupClient(stored.url, stored.token, stored.authMode || 'token');
} else { } else {
setAuthenticated(false); setAuthenticated(false);
} }
@@ -503,8 +503,8 @@ export function useGateway() {
loadHistory(key); loadHistory(key);
}, [loadHistory]); }, [loadHistory]);
const login = useCallback((url: string, token: string) => { const login = useCallback((url: string, token: string, authMode: AuthMode = 'token') => {
setupClient(url, token); setupClient(url, token, authMode);
}, [setupClient]); }, [setupClient]);
const deleteSession = useCallback(async (key: string) => { const deleteSession = useCallback(async (key: string) => {

View File

@@ -0,0 +1,62 @@
/**
* @vitest-environment jsdom
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { copyToClipboard } from '../clipboard';
describe('copyToClipboard', () => {
beforeEach(() => {
// jsdom doesn't define execCommand — add it so we can spy on it
if (!document.execCommand) {
(document as unknown as Record<string, unknown>).execCommand = () => false;
}
});
afterEach(() => {
vi.restoreAllMocks();
});
it('uses navigator.clipboard.writeText when available', async () => {
const writeText = vi.fn().mockResolvedValue(undefined);
Object.assign(navigator, { clipboard: { writeText } });
const result = await copyToClipboard('hello');
expect(writeText).toHaveBeenCalledWith('hello');
expect(result).toBe(true);
});
it('falls back to execCommand when clipboard API throws', async () => {
const writeText = vi.fn().mockRejectedValue(new Error('denied'));
Object.assign(navigator, { clipboard: { writeText } });
vi.spyOn(document, 'execCommand').mockReturnValue(true);
const result = await copyToClipboard('fallback text');
expect(document.execCommand).toHaveBeenCalledWith('copy');
expect(result).toBe(true);
});
it('falls back to execCommand when clipboard API is undefined', async () => {
Object.assign(navigator, { clipboard: undefined });
vi.spyOn(document, 'execCommand').mockReturnValue(true);
const result = await copyToClipboard('no clipboard');
expect(document.execCommand).toHaveBeenCalledWith('copy');
expect(result).toBe(true);
});
it('returns false when execCommand returns false', async () => {
Object.assign(navigator, { clipboard: undefined });
vi.spyOn(document, 'execCommand').mockReturnValue(false);
const result = await copyToClipboard('fail');
expect(result).toBe(false);
});
it('returns false when both methods throw', async () => {
Object.assign(navigator, { clipboard: { writeText: vi.fn().mockRejectedValue(new Error()) } });
vi.spyOn(document, 'execCommand').mockImplementation(() => { throw new Error('not supported'); });
const result = await copyToClipboard('total fail');
expect(result).toBe(false);
});
});

View File

@@ -47,7 +47,7 @@ describe('storeCredentials', () => {
storeCredentials('wss://gw', 'tok'); storeCredentials('wss://gw', 'tok');
expect(localStorageMock.setItem).toHaveBeenCalledWith( expect(localStorageMock.setItem).toHaveBeenCalledWith(
'pinchchat_credentials', 'pinchchat_credentials',
JSON.stringify({ url: 'wss://gw', token: 'tok' }), JSON.stringify({ url: 'wss://gw', token: 'tok', authMode: 'token' }),
); );
}); });
}); });

View File

@@ -1,6 +1,15 @@
const STORAGE_KEY = 'pinchchat_credentials'; const STORAGE_KEY = 'pinchchat_credentials';
export function getStoredCredentials(): { url: string; token: string } | null { export type AuthMode = 'token' | 'password';
export interface StoredCredentials {
url: string;
token: string;
/** Auth mode — defaults to 'token' for backward compatibility */
authMode?: AuthMode;
}
export function getStoredCredentials(): StoredCredentials | null {
try { try {
const raw = localStorage.getItem(STORAGE_KEY); const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return null; if (!raw) return null;
@@ -12,8 +21,8 @@ export function getStoredCredentials(): { url: string; token: string } | null {
return null; return null;
} }
export function storeCredentials(url: string, token: string) { export function storeCredentials(url: string, token: string, authMode: AuthMode = 'token') {
localStorage.setItem(STORAGE_KEY, JSON.stringify({ url, token })); localStorage.setItem(STORAGE_KEY, JSON.stringify({ url, token, authMode }));
} }
export function clearCredentials() { export function clearCredentials() {

View File

@@ -1,6 +1,7 @@
import { genId } from './utils'; import { genId } from './utils';
import type { DeviceIdentity } from './deviceIdentity'; import type { DeviceIdentity } from './deviceIdentity';
import { buildDeviceAuthPayload, signPayload } from './deviceIdentity'; import { buildDeviceAuthPayload, signPayload } from './deviceIdentity';
import type { AuthMode } from './credentials';
/** Debug logger — enable with localStorage.setItem('pinchchat:debug', '1') */ /** Debug logger — enable with localStorage.setItem('pinchchat:debug', '1') */
const isDebug = () => { const isDebug = () => {
@@ -41,17 +42,20 @@ export class GatewayClient {
private wsUrl: string; private wsUrl: string;
private authToken: string; private authToken: string;
private authMode: AuthMode = 'token';
private deviceIdentity: DeviceIdentity | null = null; private deviceIdentity: DeviceIdentity | null = null;
constructor(wsUrl?: string, authToken?: string) { constructor(wsUrl?: string, authToken?: string, authMode?: AuthMode) {
this.wsUrl = wsUrl || `ws://${window.location.hostname}:18789`; this.wsUrl = wsUrl || `ws://${window.location.hostname}:18789`;
this.authToken = authToken || ''; this.authToken = authToken || '';
this.authMode = authMode || 'token';
} }
/** Update credentials (e.g. after login). Does not reconnect automatically. */ /** Update credentials (e.g. after login). Does not reconnect automatically. */
setCredentials(wsUrl: string, authToken: string) { setCredentials(wsUrl: string, authToken: string, authMode?: AuthMode) {
this.wsUrl = wsUrl; this.wsUrl = wsUrl;
this.authToken = authToken; this.authToken = authToken;
if (authMode) this.authMode = authMode;
} }
/** Set the device identity for signed connect handshakes. */ /** Set the device identity for signed connect handshakes. */
@@ -154,7 +158,7 @@ export class GatewayClient {
caps: [], caps: [],
commands: [], commands: [],
permissions: {}, permissions: {},
auth: { token: this.authToken }, auth: this.authMode === 'password' ? { password: this.authToken } : { token: this.authToken },
device, device,
locale: (typeof navigator !== 'undefined' ? navigator.language : undefined) || 'en', locale: (typeof navigator !== 'undefined' ? navigator.language : undefined) || 'en',
userAgent: `pinchchat/${__APP_VERSION__}`, userAgent: `pinchchat/${__APP_VERSION__}`,

View File

@@ -14,6 +14,10 @@ const en = {
'login.gatewayUrl': 'Gateway URL', 'login.gatewayUrl': 'Gateway URL',
'login.token': 'Token', 'login.token': 'Token',
'login.tokenPlaceholder': 'Enter your gateway token', 'login.tokenPlaceholder': 'Enter your gateway token',
'login.authToken': 'Token',
'login.authPassword': 'Password',
'login.password': 'Password',
'login.passwordPlaceholder': 'Enter your gateway password',
'login.connect': 'Connect', 'login.connect': 'Connect',
'login.connecting': 'Connecting…', 'login.connecting': 'Connecting…',
'login.showToken': 'Show token', 'login.showToken': 'Show token',
@@ -191,6 +195,10 @@ const fr: Record<keyof typeof en, string> = {
'login.gatewayUrl': 'URL de la gateway', 'login.gatewayUrl': 'URL de la gateway',
'login.token': 'Token', 'login.token': 'Token',
'login.tokenPlaceholder': 'Entrez votre token gateway', 'login.tokenPlaceholder': 'Entrez votre token gateway',
'login.authToken': 'Token',
'login.authPassword': 'Mot de passe',
'login.password': 'Mot de passe',
'login.passwordPlaceholder': 'Entrez votre mot de passe gateway',
'login.connect': 'Connexion', 'login.connect': 'Connexion',
'login.connecting': 'Connexion…', 'login.connecting': 'Connexion…',
'login.showToken': 'Afficher le token', 'login.showToken': 'Afficher le token',
@@ -353,6 +361,10 @@ const es: Record<keyof typeof en, string> = {
'login.gatewayUrl': 'URL del gateway', 'login.gatewayUrl': 'URL del gateway',
'login.token': 'Token', 'login.token': 'Token',
'login.tokenPlaceholder': 'Introduce tu token de gateway', 'login.tokenPlaceholder': 'Introduce tu token de gateway',
'login.authToken': 'Token',
'login.authPassword': 'Contraseña',
'login.password': 'Contraseña',
'login.passwordPlaceholder': 'Introduce tu contraseña de gateway',
'login.connect': 'Conectar', 'login.connect': 'Conectar',
'login.connecting': 'Conectando…', 'login.connecting': 'Conectando…',
'login.showToken': 'Mostrar token', 'login.showToken': 'Mostrar token',
@@ -517,6 +529,10 @@ const de: Record<keyof typeof en, string> = {
'login.gatewayUrl': 'Gateway-URL', 'login.gatewayUrl': 'Gateway-URL',
'login.token': 'Token', 'login.token': 'Token',
'login.tokenPlaceholder': 'Gateway-Token eingeben', 'login.tokenPlaceholder': 'Gateway-Token eingeben',
'login.authToken': 'Token',
'login.authPassword': 'Passwort',
'login.password': 'Passwort',
'login.passwordPlaceholder': 'Gateway-Passwort eingeben',
'login.connect': 'Verbinden', 'login.connect': 'Verbinden',
'login.connecting': 'Verbinde…', 'login.connecting': 'Verbinde…',
'login.showToken': 'Token anzeigen', 'login.showToken': 'Token anzeigen',
@@ -679,6 +695,10 @@ const ja: Record<keyof typeof en, string> = {
'login.gatewayUrl': 'ゲートウェイURL', 'login.gatewayUrl': 'ゲートウェイURL',
'login.token': 'トークン', 'login.token': 'トークン',
'login.tokenPlaceholder': 'ゲートウェイトークンを入力', 'login.tokenPlaceholder': 'ゲートウェイトークンを入力',
'login.authToken': 'トークン',
'login.authPassword': 'パスワード',
'login.password': 'パスワード',
'login.passwordPlaceholder': 'ゲートウェイパスワードを入力',
'login.connect': '接続', 'login.connect': '接続',
'login.connecting': '接続中…', 'login.connecting': '接続中…',
'login.showToken': 'トークンを表示', 'login.showToken': 'トークンを表示',
@@ -841,6 +861,10 @@ const pt: Record<keyof typeof en, string> = {
'login.gatewayUrl': 'URL do Gateway', 'login.gatewayUrl': 'URL do Gateway',
'login.token': 'Token', 'login.token': 'Token',
'login.tokenPlaceholder': 'Insira o token do gateway', 'login.tokenPlaceholder': 'Insira o token do gateway',
'login.authToken': 'Token',
'login.authPassword': 'Senha',
'login.password': 'Senha',
'login.passwordPlaceholder': 'Insira a senha do gateway',
'login.connect': 'Conectar', 'login.connect': 'Conectar',
'login.connecting': 'Conectando…', 'login.connecting': 'Conectando…',
'login.showToken': 'Mostrar token', 'login.showToken': 'Mostrar token',
@@ -1003,6 +1027,10 @@ const zh: Record<keyof typeof en, string> = {
'login.gatewayUrl': '网关地址', 'login.gatewayUrl': '网关地址',
'login.token': '令牌', 'login.token': '令牌',
'login.tokenPlaceholder': '输入网关令牌', 'login.tokenPlaceholder': '输入网关令牌',
'login.authToken': '令牌',
'login.authPassword': '密码',
'login.password': '密码',
'login.passwordPlaceholder': '输入网关密码',
'login.connect': '连接', 'login.connect': '连接',
'login.connecting': '连接中…', 'login.connecting': '连接中…',
'login.showToken': '显示令牌', 'login.showToken': '显示令牌',
@@ -1165,6 +1193,10 @@ const it: Record<keyof typeof en, string> = {
'login.gatewayUrl': 'URL del Gateway', 'login.gatewayUrl': 'URL del Gateway',
'login.token': 'Token', 'login.token': 'Token',
'login.tokenPlaceholder': 'Inserisci il token del gateway', 'login.tokenPlaceholder': 'Inserisci il token del gateway',
'login.authToken': 'Token',
'login.authPassword': 'Password',
'login.password': 'Password',
'login.passwordPlaceholder': 'Inserisci la password del gateway',
'login.connect': 'Connetti', 'login.connect': 'Connetti',
'login.connecting': 'Connessione…', 'login.connecting': 'Connessione…',
'login.showToken': 'Mostra token', 'login.showToken': 'Mostra token',