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

fix: redirect user if they visit onboarding page without auth #1596

Merged

Conversation

ShubhamPalriwala
Copy link
Contributor

What does this PR do?

Sentry reported 46 instances of users getting a Session not Found error specifically on the Onboarding page that we have. We currently just show the user an error without any CTA. This case is possible for when a token expires or the session JWT is not valid anymore. To tackle this, we now redirect them back to the login page so that a new token can be generated and then they will be taken to the page they should be as per the normal flow.

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 8, 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 8, 2023 9:19am
formbricks-com ⬜️ Ignored (Inspect) Nov 8, 2023 9:19am

Copy link
Contributor

github-actions bot commented Nov 8, 2023

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

apps/web/app/(app)/onboarding/page.tsx

Instead of throwing an error when no environment is found for the user, it would be better to redirect the user to a page where they can create or select an environment. This would improve the user experience and make the application more robust.
Create Issue

    if (!environment) {
      redirect("/environment/select");
    }

It's a good practice to avoid using the optional chaining operator (?) when you are sure that the object is not null or undefined. In this case, since you are checking if the session exists before accessing the user id, there is no need to use the optional chaining operator when accessing the user id.
Create Issue

    const userId = session.user.id;


export default async function OnboardingPage() {
const session = await getServerSession(authOptions);
if (!session) {
throw new Error("No session found");
redirect("/auth/login");
}
const userId = session?.user.id;
Copy link
Contributor

Choose a reason for hiding this comment

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

Removed the optional chaining operator when accessing the user id, as it's unnecessary due to the preceding null check on the session object.

Suggested change
const userId = session?.user.id;
const userId = session.user.id;

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 8, 2023
Merged via the queue into main with commit c45248a Nov 8, 2023
14 checks passed
@mattinannt mattinannt deleted the shubham/sentry-redirect-if-no-session-in-onboarding branch November 8, 2023 09:35
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