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

isAuthorized not working correctly #21

Open
pavsob opened this issue Dec 20, 2024 · 0 comments
Open

isAuthorized not working correctly #21

pavsob opened this issue Dec 20, 2024 · 0 comments

Comments

@pavsob
Copy link

pavsob commented Dec 20, 2024

When not having paid subscription you won't get the unauthorized access page.

This is for several reasons:

  1. on the dashboard layout.tsx -> code is checking for authorization but it's only logging not implementing logic to prevent access to the dashboard. To fix it do this in the DashboardLayout:

if (!authorized) { console.log('authorized check fired') return <NotAuthorized /> }

  1. in the utils -> isAuthorized.ts it is looking into the wrong config file, fix the config file import:

import config from "@/config";

  1. The logic that is checking for the subscription is also broken when someone subscribes and then cancles and then subscribes again it won't count it as active membership as it will retrieve all the subscriptions even the cancelled one so alter the logic there to this:
    const { data, error } = await supabase
      .from("subscriptions")
      .select("*")
      .eq("user_id", userId)
      .eq("status", "active")
      .limit(1);

    if (error?.code)
      return {
        authorized: false,
        message: error.message,
      };
    console.log('data: ', data)

    if (data && data.length > 0) {
      return {
        authorized: true,
        message: "User is subscribed",
      };
    }
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

No branches or pull requests

1 participant