I created a support ticket with Auth0 about this but figured it would be a good idea to see if someone here has also tried to do something similar.
I am building a subscription Web App with Next.js and stripe. I am trying to limit user access to my application based on if the user has an active subscription or not. My web app requires all users to register before they can access any content and once they register and log in I have some auth0 actions which create a stripe customer id for them and check stripe to see if they have an active subscription. If they do have an active subscription the action will add 'subscription_status': 'active'
or 'subscription_status': 'not-active'
to the users app_metadata if they do not have an active subscription.
What I would like to do is within my application, access this app_metadata so that I can use state to show/hide a <p>
tag that shows 'You have an active subscription'
if the users app_metadata has 'subscription_status': 'active'
and 'You do not have an active subscription'
if the users app_metadata has 'subscription_status': 'not-active'
Is there a way I can just access this data from the front end like I can with the useUser() hook and just do a console.log(user.app_metadata)?
for reference this is what I would like to do in my code:
import { useEffect, useState } from "react";
import {useUser, } from "@auth0/nextjs-auth0";
export default function Subscriber() {
// use state to determine if the user is a subscriber
// initially the user will be considered a non subscriber by default
const [subscription, setSubscription] = useState(false);
// get the user infor from auth0
const { user } = useUser();
useEffect(() => {
// get the subscription status from the user app metadata from auth0 and set the state accordingly
if (user.app_metadata.subscription_status === 'active') {
setSubscription(true);
} else {
setSubscription(false);
}
}, []);
return (
<>
<div>
<p>
{/*if the user is a subscriber then show is a subscriber else show is not a subscriber*/}
{subscription ? 'is a subscriber' : 'is not a subscriber'}
</p>
</div>
</>
);
}
is what I am trying to do even possible? If so I would love some guidance on how to achieve the desired result.
Edit: I wonder if having a user store in Airtable with the subscription_status as a field would actually be better suited for this. Then I could just call airtable right from the application and get what I need.