36 lines
715 B
TypeScript
36 lines
715 B
TypeScript
import { app, appId } from '@/agent/app.ts';
|
|
import './user/check.ts'
|
|
|
|
const checkAppId = (ctx: any, appId: string) => {
|
|
const _appId = ctx?.appId;
|
|
if (_appId) {
|
|
if (_appId !== appId) {
|
|
ctx.throw(403, 'Invalid App ID');
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
if (!app.hasRoute('auth')) {
|
|
app.route({
|
|
id: 'auth',
|
|
path: 'auth',
|
|
}).define(async (ctx) => {
|
|
// ctx.body = 'Auth Route';
|
|
if (checkAppId(ctx, appId)) {
|
|
return;
|
|
}
|
|
}).addTo(app);
|
|
|
|
app.route({
|
|
id: 'admin-auth',
|
|
path: 'admin-auth',
|
|
middleware: ['auth'],
|
|
}).define(async (ctx) => {
|
|
// ctx.body = 'Admin Auth Route';
|
|
if (checkAppId(ctx, appId)) {
|
|
return;
|
|
}
|
|
}).addTo(app);
|
|
} |