Do I check if user is paid in every request?
Unanswered
Black Norwegian Elkhound posted this in #help-forum
Black Norwegian ElkhoundOP
Should I check if the user is paid in every request? And should I have an endpoint in the backend to check if they are paid. Or is there any way to do it using NextAuth inside the JWT stuff?
My JWT Code:
My JWT Code:
async jwt({ token, user, trigger }) {
const email = user?.email || token.email;
if (user || trigger === 'update') {
if (email) {
const userData = await getOrCreateUser(email);
token.email = email;
token.name = user?.name?.split(' ')[0] || token.name;
token.pfp = user?.image || token.pfp;
token.premium = userData.premium;
}
}
return token;
},
3 Replies
American black bear
ideally after payment you should create a "session" in the database which contains information like:
type Subscription = {
createdAt: Date
expiresAt: Date
userId: relatedUserId
}
you should check if he has paid in every request that should require payment
think of it like auth, you always check if the user is logged in before he can do certain actions