Skip to content

Commit

Permalink
use logger instead of console
Browse files Browse the repository at this point in the history
Signed-off-by: Ilayda Cansin Koc <ilaydacansin@gmail.com>
  • Loading branch information
ilaydacansinkoc committed Jun 11, 2024
1 parent 851e95c commit 73e72cf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 52 deletions.
3 changes: 2 additions & 1 deletion vclogin/config/incrAuthDescriptor.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}
};
Expand Down
45 changes: 2 additions & 43 deletions vclogin/config/incrAuthPolicy.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}
};
3 changes: 2 additions & 1 deletion vclogin/config/loginPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
1 change: 1 addition & 0 deletions vclogin/generateInputDescriptor.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
const fs = require("fs");
const path = require("path");

Expand Down
13 changes: 7 additions & 6 deletions vclogin/lib/generatePresentationDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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,
);
Expand Down
3 changes: 2 additions & 1 deletion vclogin/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit 73e72cf

Please sign in to comment.