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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user existence checks in session object #1587

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

ShubhamPalriwala
Copy link
Contributor

What does this PR do?

Sentry runtime errors included these 2 pages where the id of an undefined object was being fetched resulting in a runtime error. This PR handles them both.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 馃檹

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Copy link

vercel bot commented Nov 7, 2023

The latest updates on your projects. Learn more about Vercel for Git 鈫楋笌

2 Ignored Deployments
Name Status Preview Updated (UTC)
formbricks-cloud 猬滐笍 Ignored (Inspect) Nov 7, 2023 6:37am
formbricks-com 猬滐笍 Ignored (Inspect) Nov 7, 2023 6:37am

Copy link
Contributor

github-actions bot commented Nov 7, 2023

Thank you for following the naming conventions for pull request titles! 馃檹

Copy link
Contributor

apps/web/app/(app)/environments/[environmentId]/layout.tsx

It's a good practice to check if the session and session.user exist before using it. This can prevent potential null reference exceptions which can lead to application crashes.
Create Issue

    const session = await getServerSession(authOptions);
    if (!session || !session.user) {
      return redirect(`/auth/login`);
    }
    const hasAccess = await hasUserEnvironmentAccess(session.user.id, params.environmentId);

apps/web/app/(app)/environments/[environmentId]/settings/profile/page.tsx

It's a good practice to check if the session and session.user exist before using it. This can prevent potential null reference exceptions which can lead to application crashes.
Create Issue

    const session = await getServerSession(authOptions);
    const profile = session && session.user ? await getProfile(session.user.id) : null;

Comment on lines 16 to +17
const session = await getServerSession(authOptions);
const profile = session ? await getProfile(session.user.id) : null;
const profile = session && session.user ? await getProfile(session.user.id) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check to ensure that the session and session.user exist before using it. This prevents potential null reference exceptions which can lead to application crashes.

Suggested change
const session = await getServerSession(authOptions);
const profile = session ? await getProfile(session.user.id) : null;
const profile = session && session.user ? await getProfile(session.user.id) : null;
const session = await getServerSession(authOptions);
const profile = session && session.user ? await getProfile(session.user.id) : null;

Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃槉馃檹

@mattinannt mattinannt added this pull request to the merge queue Nov 7, 2023
Merged via the queue into main with commit 27b99d9 Nov 7, 2023
14 checks passed
@mattinannt mattinannt deleted the shubham/sentry-session-user-undefined branch November 7, 2023 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants