add cookie

This commit is contained in:
xion 2024-12-13 01:51:55 +08:00
parent c00bfcf011
commit 8642ba2e90
4 changed files with 96 additions and 43 deletions

View File

@ -36,10 +36,10 @@
"@kevisual/ai-lang": "workspace:^",
"@kevisual/auth": "1.0.5",
"@kevisual/local-app-manager": "0.1.6-alpha.3",
"@kevisual/router": "^0.0.6-alpha-2",
"@kevisual/router": "^0.0.6-alpha-3",
"@types/semver": "^7.5.8",
"archiver": "^7.0.1",
"bullmq": "^5.31.2",
"bullmq": "^5.34.0",
"dayjs": "^1.11.13",
"dts-bundle-generator": "^9.5.1",
"formidable": "^3.5.2",
@ -52,7 +52,7 @@
"neo4j-driver": "^5.27.0",
"neode": "^0.4.9",
"node-fetch": "^3.3.2",
"ollama": "^0.5.10",
"ollama": "^0.5.11",
"p-queue": "^8.0.1",
"pg": "^8.13.1",
"rollup-plugin-esbuild": "^6.1.1",
@ -63,7 +63,7 @@
"strip-ansi": "^7.1.0",
"tar": "^7.4.3",
"uuid": "^11.0.3",
"zod": "^3.23.8"
"zod": "^3.24.1"
},
"devDependencies": {
"@kevisual/use-config": "^1.0.7",
@ -78,8 +78,8 @@
"@types/formidable": "^3.4.5",
"@types/jsonwebtoken": "^9.0.7",
"@types/lodash-es": "^4.17.12",
"@types/node": "^22.10.1",
"@types/react": "^19.0.0",
"@types/node": "^22.10.2",
"@types/react": "^19.0.1",
"@types/uuid": "^10.0.0",
"concurrently": "^9.1.0",
"cross-env": "^7.0.3",

95
pnpm-lock.yaml generated
View File

@ -33,10 +33,10 @@ importers:
version: 1.0.5
'@kevisual/local-app-manager':
specifier: 0.1.6-alpha.3
version: 0.1.6-alpha.3(@kevisual/router@0.0.6-alpha-2)(@kevisual/types@0.0.1)(@kevisual/use-config@1.0.7)
version: 0.1.6-alpha.3(@kevisual/router@0.0.6-alpha-3)(@kevisual/types@0.0.1)(@kevisual/use-config@1.0.7)
'@kevisual/router':
specifier: ^0.0.6-alpha-2
version: 0.0.6-alpha-2
specifier: ^0.0.6-alpha-3
version: 0.0.6-alpha-3
'@types/semver':
specifier: ^7.5.8
version: 7.5.8
@ -44,8 +44,8 @@ importers:
specifier: ^7.0.1
version: 7.0.1
bullmq:
specifier: ^5.31.2
version: 5.31.2
specifier: ^5.34.0
version: 5.34.0
dayjs:
specifier: ^1.11.13
version: 1.11.13
@ -83,8 +83,8 @@ importers:
specifier: ^3.3.2
version: 3.3.2
ollama:
specifier: ^0.5.10
version: 0.5.10
specifier: ^0.5.11
version: 0.5.11
p-queue:
specifier: ^8.0.1
version: 8.0.1
@ -116,8 +116,8 @@ importers:
specifier: ^11.0.3
version: 11.0.3
zod:
specifier: ^3.23.8
version: 3.23.8
specifier: ^3.24.1
version: 3.24.1
devDependencies:
'@kevisual/use-config':
specifier: ^1.0.7
@ -156,11 +156,11 @@ importers:
specifier: ^4.17.12
version: 4.17.12
'@types/node':
specifier: ^22.10.1
version: 22.10.1
specifier: ^22.10.2
version: 22.10.2
'@types/react':
specifier: ^19.0.0
version: 19.0.0
specifier: ^19.0.1
version: 19.0.1
'@types/uuid':
specifier: ^10.0.0
version: 10.0.0
@ -1052,6 +1052,9 @@ packages:
'@kevisual/router@0.0.6-alpha-2':
resolution: {integrity: sha512-P9rarSQG0tp8L3GSgivYZQ//SugEt6/YCzNE8087KsRIdF1g0v8rXGfi1G3b8cXRz/ip79Lb+caU7LsoAQhmOQ==}
'@kevisual/router@0.0.6-alpha-3':
resolution: {integrity: sha512-LvRo2QSlXeKL1qFuDHhKVxlT5d+RFfwJai8gWHmaaB6o+kEm+tzy91DJUHYveqcxbHaggGmXi2MZYs4161DfwA==}
'@kevisual/types@0.0.1':
resolution: {integrity: sha512-3Wn6WjpfbOGTqIVS7YQ/0CIQEEbZEp+uCTbIWqTZyuytiA/Xoglr5kG3AbTuLFQ81AvfxjEjp5dAnFub+2IhhQ==}
@ -1510,11 +1513,14 @@ packages:
'@types/node@22.10.1':
resolution: {integrity: sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==}
'@types/node@22.10.2':
resolution: {integrity: sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==}
'@types/node@22.9.0':
resolution: {integrity: sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==}
'@types/react@19.0.0':
resolution: {integrity: sha512-MY3oPudxvMYyesqs/kW1Bh8y9VqSmf+tzqw3ae8a9DZW68pUe3zAdHeI1jc6iAysuRdACnVknHP8AhwD4/dxtg==}
'@types/react@19.0.1':
resolution: {integrity: sha512-YW6614BDhqbpR5KtUYzTA+zlA7nayzJRA9ljz9CQoxthR0sDisYZLuvSMsil36t4EH/uAt8T52Xb4sVw17G+SQ==}
'@types/readdir-glob@1.1.5':
resolution: {integrity: sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg==}
@ -1753,8 +1759,8 @@ packages:
buffer@6.0.3:
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
bullmq@5.31.2:
resolution: {integrity: sha512-MUW6j1V79NRnrGZtxKyfyTv/YJ5Ljy0IrbMElpuQNCaLXoXEcCtU6kwdGiHxso9dUi1Wp4yo3GYEGg8vyWWLsw==}
bullmq@5.34.0:
resolution: {integrity: sha512-TyzeYDkIGkooYUn/P1CeiJW3Am1TboC3unwhlg1cJIwKksoyuRp97TkHyCZcwLchXbYCUtsGBZFUYf/lTAhdSg==}
cacache@15.3.0:
resolution: {integrity: sha512-VVdYzXEn+cnbXpFgWs5hTT7OScegHVmLhJIR8Ufqk3iFD6A6j5iSX1KuBTfNEv4tdJWE2PzA6IVFtcLC7fN9wQ==}
@ -3029,6 +3035,9 @@ packages:
ollama@0.5.10:
resolution: {integrity: sha512-M5O4u6S6yZeeKFrKA7ZfGGLjK54otOVGPrOUc3N64zSTpz9J+x/nh93dmD6Py7YLgXzq9I6Nq+PDDoaqJuV3LQ==}
ollama@0.5.11:
resolution: {integrity: sha512-lDAKcpmBU3VAOGF05NcQipHNKTdpKfAHpZ7bjCsElkUkmX7SNZImi6lwIxz/l1zQtLq0S3wuLneRuiXxX2KIew==}
once@1.4.0:
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
@ -3998,6 +4007,9 @@ packages:
zod@3.23.8:
resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==}
zod@3.24.1:
resolution: {integrity: sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==}
snapshots:
'@abearxiong/router@0.0.1-alpha.36':
@ -4829,9 +4841,9 @@ snapshots:
'@kevisual/auth@1.0.5': {}
'@kevisual/local-app-manager@0.1.6-alpha.3(@kevisual/router@0.0.6-alpha-2)(@kevisual/types@0.0.1)(@kevisual/use-config@1.0.7)':
'@kevisual/local-app-manager@0.1.6-alpha.3(@kevisual/router@0.0.6-alpha-3)(@kevisual/types@0.0.1)(@kevisual/use-config@1.0.7)':
dependencies:
'@kevisual/router': 0.0.6-alpha-2
'@kevisual/router': 0.0.6-alpha-3
'@kevisual/types': 0.0.1
'@kevisual/use-config': 1.0.7
@ -4844,6 +4856,15 @@ snapshots:
- bufferutil
- utf-8-validate
'@kevisual/router@0.0.6-alpha-3':
dependencies:
path-to-regexp: 8.2.0
selfsigned: 2.4.1
ws: 8.18.0
transitivePeerDependencies:
- bufferutil
- utf-8-validate
'@kevisual/types@0.0.1': {}
'@kevisual/use-config@1.0.7': {}
@ -5237,7 +5258,7 @@ snapshots:
'@types/cors@2.8.17':
dependencies:
'@types/node': 22.10.1
'@types/node': 22.10.2
'@types/crypto-js@4.2.2': {}
@ -5249,24 +5270,24 @@ snapshots:
'@types/formidable@3.4.5':
dependencies:
'@types/node': 22.10.1
'@types/node': 22.10.2
'@types/fs-extra@8.1.5':
dependencies:
'@types/node': 22.10.1
'@types/node': 22.10.2
'@types/glob@7.2.0':
dependencies:
'@types/minimatch': 5.1.2
'@types/node': 22.10.1
'@types/node': 22.10.2
'@types/http-proxy@1.17.15':
dependencies:
'@types/node': 22.10.1
'@types/node': 22.10.2
'@types/jsonwebtoken@9.0.7':
dependencies:
'@types/node': 22.10.1
'@types/node': 22.10.2
'@types/lodash-es@4.17.12':
dependencies:
@ -5280,12 +5301,12 @@ snapshots:
'@types/node-fetch@2.6.11':
dependencies:
'@types/node': 22.10.1
'@types/node': 22.10.2
form-data: 4.0.0
'@types/node-forge@1.3.11':
dependencies:
'@types/node': 22.10.1
'@types/node': 22.10.2
'@types/node@18.19.53':
dependencies:
@ -5295,17 +5316,21 @@ snapshots:
dependencies:
undici-types: 6.20.0
'@types/node@22.10.2':
dependencies:
undici-types: 6.20.0
'@types/node@22.9.0':
dependencies:
undici-types: 6.19.8
'@types/react@19.0.0':
'@types/react@19.0.1':
dependencies:
csstype: 3.1.3
'@types/readdir-glob@1.1.5':
dependencies:
'@types/node': 22.10.1
'@types/node': 22.10.2
'@types/resolve@1.20.2': {}
@ -5558,7 +5583,7 @@ snapshots:
base64-js: 1.5.1
ieee754: 1.2.1
bullmq@5.31.2:
bullmq@5.34.0:
dependencies:
cron-parser: 4.9.0
ioredis: 5.4.1
@ -5886,7 +5911,7 @@ snapshots:
dependencies:
'@types/cookie': 0.4.1
'@types/cors': 2.8.17
'@types/node': 22.10.1
'@types/node': 22.10.2
accepts: 1.3.8
base64id: 2.0.0
cookie: 0.4.2
@ -6993,6 +7018,10 @@ snapshots:
dependencies:
whatwg-fetch: 3.6.20
ollama@0.5.11:
dependencies:
whatwg-fetch: 3.6.20
once@1.4.0:
dependencies:
wrappy: 1.0.2
@ -8073,7 +8102,7 @@ snapshots:
wkx@0.5.0:
dependencies:
'@types/node': 22.10.1
'@types/node': 22.10.2
wrap-ansi@7.0.0:
dependencies:
@ -8135,3 +8164,5 @@ snapshots:
zod: 3.23.8
zod@3.23.8: {}
zod@3.24.1: {}

View File

@ -7,7 +7,6 @@ app
path: 'user',
key: 'me',
middleware: ['auth'],
isDebug: true,
})
.define(async (ctx) => {
const tokenUser = ctx.state?.tokenUser || {};
@ -39,9 +38,12 @@ app
if (!user && email) {
user = await User.findOne({ where: { email } });
}
console.log('user logiin', ctx.query)
console.log('user logiin', user)
console.log('users', (await User.findAll()).map(u => u.username))
console.log('user logiin', ctx.query);
console.log('user logiin', user);
console.log(
'users',
(await User.findAll()).map((u) => u.username),
);
if (!user) {
ctx.throw(500, 'Login Failed');
}
@ -49,10 +51,30 @@ app
ctx.throw(500, 'Password error');
}
const token = await user.createToken();
ctx.res.cookie('token', token.token, {
maxAge: token.expireTime,
domain: 'xiongxiao.me',
sameSite: 'lax',
httpOnly: true,
});
ctx.body = token;
})
.addTo(app);
app
.route({
path: 'user',
key: 'logout',
})
.define(async (ctx) => {
ctx.res.cookie('token', '', {
maxAge: 0,
domain: 'xiongxiao.me',
sameSite: 'lax',
httpOnly: true,
});
})
.addTo(app);
app
.route('user', 'auth')
.define(async (ctx) => {