Skip to content

Commit

Permalink
fix[app]: patch to fix build error (passportxyz#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
nutrina authored Jan 31, 2024
1 parent d0717f8 commit d8c5a82
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions app/context/datastoreConnectionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,31 +138,32 @@ export const useDatastoreConnection = () => {
// The sessions are bound to an ETH address, this is why we use the address in the session key
sessionKey = `didsession-${address}`;
dbCacheTokenKey = `dbcache-token-${address}`;
const sessionStr = window.localStorage.getItem(sessionKey);
let session: DIDSession | undefined = undefined;
try {
if (sessionStr) {
session = await DIDSession.fromSession(sessionStr);
}
} catch (error) {
console.log("Error parsing session from localStorage:", error);
window.localStorage.removeItem(sessionKey);
}

if (
true || // Hotfix: Hardcoding this here, as we always want a session created by DIDSession.get ... (at least for now)
!session ||
session.isExpired ||
session.expireInSecs < 3600 ||
!session.hasSession ||
Date.now() - new Date(session?.cacao?.p?.iat).getTime() >
MAX_VALID_DID_SESSION_AGE - BUFFER_TIME_BEFORE_EXPIRATION
) {
// session = await DIDSession.authorize(authMethod, { resources: ["ceramic://*"] });
session = await DIDSession.get(accountId, authMethod, { resources: ["ceramic://*"] });
// Store the session in localstorage
// window.localStorage.setItem(sessionKey, session.serialize());
}
// const sessionStr = window.localStorage.getItem(sessionKey);
// let session: DIDSession | undefined = undefined;
// try {
// if (sessionStr) {
// session = await DIDSession.fromSession(sessionStr);
// }
// } catch (error) {
// console.log("Error parsing session from localStorage:", error);
// window.localStorage.removeItem(sessionKey);
// }

// if (
// true
// // || // Hotfix: Hardcoding this here, as we always want a session created by DIDSession.get ... (at least for now)
// // !session ||
// // session.isExpired ||
// // session.expireInSecs < 3600 ||
// // !session.hasSession ||
// // Date.now() - new Date(session?.cacao?.p?.iat).getTime() >
// // MAX_VALID_DID_SESSION_AGE - BUFFER_TIME_BEFORE_EXPIRATION
// ) {
// // session = await DIDSession.authorize(authMethod, { resources: ["ceramic://*"] });
// // Store the session in localstorage
// // window.localStorage.setItem(sessionKey, session.serialize());
// }
let session: DIDSession = await DIDSession.get(accountId, authMethod, { resources: ["ceramic://*"] });
if (session) {
await loadDbAccessToken(address, session.did);
setDid(session.did);
Expand Down

0 comments on commit d8c5a82

Please sign in to comment.