-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-access-context.js
More file actions
65 lines (54 loc) · 2.15 KB
/
debug-access-context.js
File metadata and controls
65 lines (54 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Debug script to check user access context
// Run with: node debug-access-context.js <clerk_user_id>
import { createClient } from "@supabase/supabase-js";
import { resolveAccessContext } from "./packages/shared-access-context/dist/index.js";
const SUPABASE_URL =
process.env.SUPABASE_URL || "https://einhgkqmxbkgdohwfayv.supabase.co";
const SUPABASE_KEY = process.env.SUPABASE_SERVICE_ROLE_KEY;
if (!SUPABASE_KEY) {
console.error("Missing SUPABASE_SERVICE_ROLE_KEY");
process.exit(1);
}
const clerkUserId = process.argv[2];
if (!clerkUserId) {
console.error("Usage: node debug-access-context.js <clerk_user_id>");
process.exit(1);
}
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
console.log(`🔍 Debugging access context for Clerk User ID: ${clerkUserId}`);
async function debug() {
try {
const context = await resolveAccessContext(supabase, clerkUserId);
console.log("\n📊 Access Context:");
console.log(` Identity User ID: ${context.identityUserId}`);
console.log(` Recruiter ID: ${context.recruiterId}`);
console.log(` Candidate ID: ${context.candidateId}`);
console.log(` Roles: [${context.roles.join(", ")}]`);
console.log(
` Organization IDs: [${context.organizationIds.join(", ")}]`,
);
console.log(` Company IDs: [${context.companyIds.join(", ")}]`);
console.log(` Firm IDs: [${context.firmIds.join(", ")}]`);
console.log(` Platform Admin: ${context.isPlatformAdmin}`);
console.log(` Error: ${context.error || "none"}`);
// Check raw data
const { data: user } = await supabase
.from("users")
.select(
`
id,
clerk_user_id,
email,
memberships!memberships_user_id_fkey1(role_name, organization_id, company_id),
user_roles!user_roles_user_id_fkey(role_name, role_entity_id)
`,
)
.eq("clerk_user_id", clerkUserId)
.single();
console.log("\n📋 Raw Database Data:");
console.log("User:", user);
} catch (error) {
console.error("Error:", error);
}
}
debug();