debug: comprehensive logging to trace auth
Deploy to route.crispygoat.com / deploy (push) Successful in 3m24s
Deploy to route.crispygoat.com / deploy (push) Successful in 3m24s
This commit is contained in:
@@ -39,6 +39,7 @@ export async function getAdminUser(): Promise<AdminUser | null> {
|
|||||||
let sessionEmail: string | null = null;
|
let sessionEmail: string | null = null;
|
||||||
try {
|
try {
|
||||||
const { data: session } = await getSession();
|
const { data: session } = await getSession();
|
||||||
|
console.log("[admin-permissions] Full session:", JSON.stringify(session));
|
||||||
sessionEmail = session?.user?.email ?? null;
|
sessionEmail = session?.user?.email ?? null;
|
||||||
console.log("[admin-permissions] Session email:", sessionEmail);
|
console.log("[admin-permissions] Session email:", sessionEmail);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -46,18 +47,25 @@ export async function getAdminUser(): Promise<AdminUser | null> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sessionEmail) return null;
|
if (!sessionEmail) {
|
||||||
|
console.log("[admin-permissions] No session email - returning null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await withPlatformAdmin(async (db) => {
|
return await withPlatformAdmin(async (db) => {
|
||||||
|
console.log("[admin-permissions] Looking for user with email:", sessionEmail.toLowerCase());
|
||||||
const userRows = await db
|
const userRows = await db
|
||||||
.select()
|
.select()
|
||||||
.from(adminUsers)
|
.from(adminUsers)
|
||||||
.where(eq(adminUsers.email, sessionEmail.toLowerCase()))
|
.where(eq(adminUsers.email, sessionEmail.toLowerCase()))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
console.log("[admin-permissions] User rows found:", userRows.length);
|
console.log("[admin-permissions] User rows found:", userRows.length, userRows);
|
||||||
const user = userRows[0];
|
const user = userRows[0];
|
||||||
if (!user) return null;
|
if (!user) {
|
||||||
|
console.log("[admin-permissions] User not found in admin_users");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const membershipRows = await db
|
const membershipRows = await db
|
||||||
.select({
|
.select({
|
||||||
@@ -73,7 +81,7 @@ export async function getAdminUser(): Promise<AdminUser | null> {
|
|||||||
.where(eq(adminUserBrands.adminUserId, user.id))
|
.where(eq(adminUserBrands.adminUserId, user.id))
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
console.log("[admin-permissions] Membership rows found:", membershipRows.length);
|
console.log("[admin-permissions] Membership rows found:", membershipRows.length, membershipRows);
|
||||||
if (membershipRows.length === 0) {
|
if (membershipRows.length === 0) {
|
||||||
// Signed in but not provisioned for any brand.
|
// Signed in but not provisioned for any brand.
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user