Skip to content

Commit

Permalink
Debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
datajohnson committed Jul 24, 2024
1 parent c610b7d commit de50a66
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/api/src/middleware/authz.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ export const checkJwt = jwt({

// Validate the audience and the issuer.
audience: AUTH0_AUDIENCE,
issuer: [`${AUTH0_DOMAIN}/`],
issuer: `${AUTH0_DOMAIN}/`,
algorithms: ["RS256"],
});

export async function loadUser(req: Request, res: Response, next: NextFunction) {
const db = new UserService();

console.log("loadUser");

let sub = req.auth.sub;
const token = req.headers.authorization || "";
let u = await db.getBySub(sub);

console.log("loadUser1", u);

if (u) {
req.user = { ...req.auth, ...u };
return next();
Expand All @@ -37,6 +41,8 @@ export async function loadUser(req: Request, res: Response, next: NextFunction)
await axios
.get(`${AUTH0_DOMAIN}/userinfo`, { headers: { authorization: token } })
.then(async (resp: any) => {
console.log("loadUser2", resp);

if (resp.data && resp.data.sub) {
let email = resp.data.email;
let first_name = resp.data.given_name;
Expand All @@ -45,6 +51,8 @@ export async function loadUser(req: Request, res: Response, next: NextFunction)

let u = await db.getBySub(sub);

console.log("loadUser3", u);

if (u) {
req.user = { ...req.auth, ...u };
} else {
Expand All @@ -67,7 +75,9 @@ export async function loadUser(req: Request, res: Response, next: NextFunction)
return next();
}

/* u = await db.create({
console.log("loadUser4", u);

u = await db.create({
EMAIL: email,
USER_ID: sub,
STATUS: UserStatus.INACTIVE,
Expand All @@ -77,7 +87,7 @@ export async function loadUser(req: Request, res: Response, next: NextFunction)
IS_ADMIN: "N",
ROLE: "",
});
req.user = { ...req.user, ...u }; */
req.user = { ...req.user, ...u };
}
} else {
console.log("Payload from Auth0 is strange or failed for", req.auth);
Expand Down

0 comments on commit de50a66

Please sign in to comment.