fix: fix login bugs
This commit is contained in:
@@ -3,6 +3,7 @@ import { User } from '@/models/user.ts';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { CustomError } from '@kevisual/router';
|
||||
import { backupUserA, deleteUser, mvUserAToUserB } from '@/routes/file/index.ts';
|
||||
import { AppModel } from '@/routes/app-manager/index.ts';
|
||||
// import { mvAppFromUserAToUserB } from '@/routes/app-manager/admin/mv-user-app.ts';
|
||||
|
||||
export const checkUsername = (username: string) => {
|
||||
@@ -47,6 +48,12 @@ app
|
||||
await backupUserA(oldName, user.id); // 备份文件数据
|
||||
await mvUserAToUserB(oldName, newName, true); // 迁移文件数据
|
||||
// await mvAppFromUserAToUserB(oldName, newName); // 迁移应用数据
|
||||
|
||||
if (['org', 'user'].includes(user.type)) {
|
||||
const type = user.type === 'org' ? 'org' : 'user';
|
||||
await User.clearUserToken(user.id, type); // 清除旧token
|
||||
}
|
||||
await AppModel.moveToNewUser(oldName, newName); // 更新用户数据
|
||||
} catch (error) {
|
||||
console.error('迁移文件数据失败', error);
|
||||
ctx.throw(500, 'Failed to change username');
|
||||
|
||||
@@ -80,12 +80,17 @@ export const clearCookie = (ctx: any) => {
|
||||
if (!domain) {
|
||||
return;
|
||||
}
|
||||
ctx.res.cookie('token', '', {
|
||||
maxAge: 0,
|
||||
domain,
|
||||
sameSite: 'lax',
|
||||
httpOnly: true,
|
||||
});
|
||||
const browser = ctx.req.headers['user-agent'];
|
||||
const isBrowser = browser.includes('Mozilla'); // 浏览器
|
||||
if (isBrowser && ctx.res.cookie) {
|
||||
ctx.res.cookie('token', '_', {
|
||||
maxAge: 1,
|
||||
domain,
|
||||
path: '/',
|
||||
sameSite: 'lax',
|
||||
httpOnly: true,
|
||||
});
|
||||
}
|
||||
};
|
||||
app
|
||||
.route({
|
||||
|
||||
Reference in New Issue
Block a user