Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling for JSON.parse() in initMiro.ts #165

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion examples/monetization-with-stripe/initMiro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export default function initMiro(
const tokensCookie = "miro_tokens";
const userIdCookie = "miro_user_id";

let userId;

try {
userId = JSON.parse(request.cookies[tokensCookie] || "null")?.userId
} catch {
userId = null
}

bishopwm marked this conversation as resolved.
Show resolved Hide resolved
// setup a Miro instance that loads tokens from cookies
return {
miro: new Miro({
Expand All @@ -42,6 +50,6 @@ export default function initMiro(
},
},
}),
userId: JSON.parse(request.cookies[tokensCookie] || "null")?.userId,
userId,
};
}