You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Alright guys I need your help. So I have been trying for the last week or so to try to find the best way to check if an authenticated user has an active subscription or not. If he doesn't have it, he gets redirected to the route "/choose-plan". First I tried to get the user.id through withUserSSR and then search for an active subscription with the id like this
whenUnauthed: AuthAction.REDIRECT_TO_LOGIN,
})(async ({ AuthUser }) => { // AuthUser is provided by withUserSSR
if (!AuthUser.id) { // Use AuthUser.id instead of user.id
// If user is not authenticated, you can redirect or return null props
return {
redirect: {
destination: '/login',
permanent: false,
},
};
}
const firestore = getFirestore();
// Use Firestore SDK to check the user's subscription status
const q = query(
collection(firestore, 'customers', AuthUser.id, 'subscriptions'),
orderBy('created', 'desc'),
limit(1)
);
const querySnapshot = await getDocs(q);
if (querySnapshot.empty) {
return {
redirect: {
destination: '/choose-plan',
permanent: false,
},
};
}
return {
props: {},
};
});
But that failed because the user.id was always undefined. That's why I decided to to save the uid when the user successfully logs in with the cookies and then through context gets the uid from the cookies and makes the database request. The only problem with this is that I have to change my security rules to something like this
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Alright guys I need your help. So I have been trying for the last week or so to try to find the best way to check if an authenticated user has an active subscription or not. If he doesn't have it, he gets redirected to the route "/choose-plan". First I tried to get the user.id through withUserSSR and then search for an active subscription with the id like this
But that failed because the user.id was always undefined. That's why I decided to to save the uid when the user successfully logs in with the cookies and then through context gets the uid from the cookies and makes the database request. The only problem with this is that I have to change my security rules to something like this
(https://firebase.google.com/docs/database/admin/start#authenticate-with-limited-privileges).
My question is now if that method is secure or not. If not, please show me the right way
Beta Was this translation helpful? Give feedback.
All reactions