fix: bypass auth in dev mode and add mock session for development
Add DEV_MODE env var check to return mock admin session when auth is unavailable, hostname-based middleware bypass for dev domain, and window.location.href for login redirect to ensure cookies are sent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b389d8b482
commit
3cd5b05c46
2 changed files with 20 additions and 4 deletions
|
|
@ -68,6 +68,8 @@ services:
|
||||||
image: forgejo.wulfconsulting.cloud/lorentz/quest-vorteq:dev
|
image: forgejo.wulfconsulting.cloud/lorentz/quest-vorteq:dev
|
||||||
container_name: vorteq-dev
|
container_name: vorteq-dev
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
extra_hosts:
|
||||||
|
- "wi-e10test:10.77.0.217"
|
||||||
networks:
|
networks:
|
||||||
- web
|
- web
|
||||||
environment:
|
environment:
|
||||||
|
|
@ -77,6 +79,12 @@ services:
|
||||||
REDIS_URL: redis://redis:6379/0
|
REDIS_URL: redis://redis:6379/0
|
||||||
BETTER_AUTH_SECRET: ${DEV_AUTH_SECRET}
|
BETTER_AUTH_SECRET: ${DEV_AUTH_SECRET}
|
||||||
BETTER_AUTH_URL: https://${DEV_DOMAIN}
|
BETTER_AUTH_URL: https://${DEV_DOMAIN}
|
||||||
|
MSSQL_HOST: ${DB_HOST}
|
||||||
|
MSSQL_DATABASE: Epicor10Live
|
||||||
|
MSSQL_USER: ${DB_USERNAME_RO}
|
||||||
|
MSSQL_PASSWORD: ${DB_PASSWORD_RO}
|
||||||
|
MSSQL_PORT: "1433"
|
||||||
|
PORTAL_DB_NAME: ${DB_DATABASE}
|
||||||
PORT: 3000
|
PORT: 3000
|
||||||
labels:
|
labels:
|
||||||
- "traefik.enable=true"
|
- "traefik.enable=true"
|
||||||
|
|
|
||||||
|
|
@ -325,6 +325,9 @@ export const PermissionRules = {
|
||||||
* Returns a mock admin session for development mode
|
* Returns a mock admin session for development mode
|
||||||
*/
|
*/
|
||||||
async function getDevSession(): Promise<QuestSession> {
|
async function getDevSession(): Promise<QuestSession> {
|
||||||
|
// Check if user has already selected a company via the session cookie
|
||||||
|
const sessionData = await getQuestSessionData();
|
||||||
|
|
||||||
// Try to find the admin user in the database
|
// Try to find the admin user in the database
|
||||||
const adminUser = await db.auth_user.findFirst({
|
const adminUser = await db.auth_user.findFirst({
|
||||||
where: { email: 'admin@vorteq.com' },
|
where: { email: 'admin@vorteq.com' },
|
||||||
|
|
@ -344,9 +347,14 @@ async function getDevSession(): Promise<QuestSession> {
|
||||||
where: { id: adminUser.auth_user_type_id },
|
where: { id: adminUser.auth_user_type_id },
|
||||||
});
|
});
|
||||||
|
|
||||||
const activeCompany = adminUser.quest_user.companies.find(
|
// Use company from session cookie if set, otherwise first active company
|
||||||
(c: (typeof adminUser.quest_user.companies)[0]) => c.company.is_active
|
let activeCompanyId = sessionData.activeCompanyId;
|
||||||
);
|
if (!activeCompanyId) {
|
||||||
|
const activeCompany = adminUser.quest_user.companies.find(
|
||||||
|
(c: (typeof adminUser.quest_user.companies)[0]) => c.company.is_active
|
||||||
|
);
|
||||||
|
activeCompanyId = activeCompany?.company.id;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user: {
|
user: {
|
||||||
|
|
@ -355,7 +363,7 @@ async function getDevSession(): Promise<QuestSession> {
|
||||||
name: adminUser.name,
|
name: adminUser.name,
|
||||||
},
|
},
|
||||||
questUserId: adminUser.quest_user.id,
|
questUserId: adminUser.quest_user.id,
|
||||||
activeCompanyId: activeCompany?.company.id,
|
activeCompanyId,
|
||||||
isSubUser: false,
|
isSubUser: false,
|
||||||
permissionRules: Object.values(PermissionRules),
|
permissionRules: Object.values(PermissionRules),
|
||||||
userType: userType?.name || 'Super Admin',
|
userType: userType?.name || 'Super Admin',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue