From 68933e1df4adee2757616da688d25c05dc52f3d4 Mon Sep 17 00:00:00 2001 From: Ilayda Cansin Koc Date: Tue, 11 Jun 2024 20:33:34 +0000 Subject: [PATCH] use logger instead of console Signed-off-by: Ilayda Cansin Koc --- vclogin/config/incrAuthDescriptor.ts | 3 +- vclogin/config/incrAuthPolicy.ts | 45 +------------------ vclogin/config/loginPolicy.ts | 3 +- vclogin/generateInputDescriptor.js | 1 + vclogin/lib/generatePresentationDefinition.ts | 13 +++--- vclogin/pages/login.tsx | 3 +- 6 files changed, 16 insertions(+), 52 deletions(-) diff --git a/vclogin/config/incrAuthDescriptor.ts b/vclogin/config/incrAuthDescriptor.ts index a544703..6f35daa 100644 --- a/vclogin/config/incrAuthDescriptor.ts +++ b/vclogin/config/incrAuthDescriptor.ts @@ -1,5 +1,6 @@ import { InputDescriptor } from "@/types/InputDescriptor"; import { promises as fs } from "fs"; +import { logger } from "@/config/logger"; export const getInputDescriptorPath = (scope: string) => { let mainPath = "./init_config/input_descriptors"; @@ -49,7 +50,7 @@ const readDescriptor = async (scope: string) => { const file = await fs?.readFile(path, "utf8"); return JSON.parse(file); } catch (error) { - console.error("Error reading policy:", error); + logger.error("Error reading policy:", error); throw error; } }; diff --git a/vclogin/config/incrAuthPolicy.ts b/vclogin/config/incrAuthPolicy.ts index 1cc7979..6af08d9 100644 --- a/vclogin/config/incrAuthPolicy.ts +++ b/vclogin/config/incrAuthPolicy.ts @@ -1,47 +1,6 @@ import { LoginPolicy } from "@/types/LoginPolicy"; import { promises as fs } from "fs"; - -const policyObj = [ - { - credentialId: "1", - type: "VerifiableId", - patterns: [ - { - issuer: "did:web:app.altme.io:issuer", - claims: [ - { - claimPath: "$.credentialSubject.firstName", - token: "id_token", - }, - { - claimPath: "$.credentialSubject.familyName", - token: "id_token", - }, - ], - }, - ], - }, - { - credentialId: "2", - type: "EmailPass", - patterns: [ - { - issuer: "did:web:app.altme.io:issuer", - claims: [ - { - claimPath: "$.credentialSubject.email", - token: "id_token", - }, - ], - constraint: { - op: "equals", - a: "$2.credentialSubject.id", - b: "$1.credentialSubject.id", - }, - }, - ], - }, -]; +import { logger } from "@/config/logger"; export const getPolicyPath = (scope: string) => { let mainPath = "./init_config/policies"; @@ -71,7 +30,7 @@ const readPolicy = async (scope: string) => { const file = await fs?.readFile(path, "utf8"); return JSON.parse(file); } catch (error) { - console.error("Error reading policy:", error); + logger.error("Error reading policy:", error); throw error; } }; diff --git a/vclogin/config/loginPolicy.ts b/vclogin/config/loginPolicy.ts index 6ad339f..7140d2b 100644 --- a/vclogin/config/loginPolicy.ts +++ b/vclogin/config/loginPolicy.ts @@ -4,13 +4,14 @@ */ import { promises as fs } from "fs"; +import { logger } from "@/config/logger"; export const getConfiguredLoginPolicy = async () => { try { const file = await fs.readFile(process.env.LOGIN_POLICY as string, "utf8"); return JSON.parse(file); } catch (error) { - console.error("Failed to read login policy:", error); + logger.error("Failed to read login policy:", error); return undefined; } }; diff --git a/vclogin/generateInputDescriptor.js b/vclogin/generateInputDescriptor.js index ddd8fa2..b60b675 100644 --- a/vclogin/generateInputDescriptor.js +++ b/vclogin/generateInputDescriptor.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const fs = require("fs"); const path = require("path"); diff --git a/vclogin/lib/generatePresentationDefinition.ts b/vclogin/lib/generatePresentationDefinition.ts index 1f76cb3..8148cbe 100644 --- a/vclogin/lib/generatePresentationDefinition.ts +++ b/vclogin/lib/generatePresentationDefinition.ts @@ -7,14 +7,15 @@ import { InputDescriptor, InputDescriptors } from "@/types/InputDescriptor"; import { LoginPolicy } from "@/types/LoginPolicy"; import { PresentationDefinition } from "@/types/PresentationDefinition"; import { promises as fs } from "fs"; +import { logger } from "@/config/logger"; var inputDescriptorOverride: any = undefined; if (process.env.PEX_DESCRIPTOR_OVERRIDE) { - fs - ?.readFile(process.env.PEX_DESCRIPTOR_OVERRIDE as string, "utf8") - .then((file) => { + fs?.readFile(process.env.PEX_DESCRIPTOR_OVERRIDE as string, "utf8").then( + (file) => { inputDescriptorOverride = JSON.parse(file); - }); + }, + ); } export const generatePresentationDefinition = ( @@ -52,12 +53,12 @@ export const generatePresentationDefinition = ( }; if (inputDescriptorOverride && !incrAuthInputDescriptor) { - console.log("Using input descriptor override", inputDescriptorOverride); + logger.debug("Using input descriptor override", inputDescriptorOverride); pd.input_descriptors = inputDescriptorOverride; return pd; } else if (incrAuthInputDescriptor) { pd.input_descriptors = incrAuthInputDescriptor; - console.log( + logger.debug( "Using input descriptor override for incremental authorization", pd, ); diff --git a/vclogin/pages/login.tsx b/vclogin/pages/login.tsx index 6bbdb35..8ac7647 100644 --- a/vclogin/pages/login.tsx +++ b/vclogin/pages/login.tsx @@ -9,6 +9,7 @@ import { useRouter } from "next/router"; import { useQRCode } from "next-qrcode"; import { useEffect } from "react"; import { keyToDID } from "@spruceid/didkit-wasm-node"; +import { logger } from "@/config/logger"; export default function Login(props: any) { const router = useRouter(); @@ -110,7 +111,7 @@ export async function getServerSideProps(context: NextPageContext) { } const did = await keyToDID("key", process.env.DID_KEY_JWK!); - console.log("DID: " + did); + logger.debug("DID: " + did); return { props: { loginId, externalUrl: process.env.EXTERNAL_URL, clientId: did },