update
This commit is contained in:
31
src/modules/user-app/user-home.ts
Normal file
31
src/modules/user-app/user-home.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import http from 'http';
|
||||
import { getLoginUser } from '@/modules/auth.ts';
|
||||
import { getUserConfig } from '@/modules/fm-manager/index.ts';
|
||||
|
||||
/**
|
||||
* 重定向到用户首页
|
||||
* @param req
|
||||
* @param res
|
||||
*/
|
||||
export const rediretHome = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
const user = await getLoginUser(req);
|
||||
if (!user?.token) {
|
||||
res.writeHead(302, { Location: '/root/login/' });
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
let redirectURL = '/root/center/';
|
||||
try {
|
||||
const token = user.token;
|
||||
const resConfig = await getUserConfig(token);
|
||||
if (resConfig.code === 200) {
|
||||
const configData = resConfig.data?.data as any;
|
||||
redirectURL = configData?.redirectURL || redirectURL;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('get resConfig user.json', error);
|
||||
} finally {
|
||||
res.writeHead(302, { Location: redirectURL });
|
||||
res.end();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user