Fix user membership state for incognito.
Run the membership reducer even for incognito. The GUI needs to differentiate between 'unfetched' (`undefined`) and 'no membership' (`''`), so we must call the action/reducer for the incognito case as well.
This commit is contained in:
parent
deb95cd443
commit
9d830615fd
1 changed files with 39 additions and 47 deletions
|
@ -114,41 +114,44 @@ function checkAuthBusy() {
|
||||||
*/
|
*/
|
||||||
export function doCheckUserOdyseeMemberships(user) {
|
export function doCheckUserOdyseeMemberships(user) {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
// get memberships for a given user
|
|
||||||
// TODO: in the future, can we specify this just to @odysee?
|
|
||||||
|
|
||||||
const response = await Lbryio.call(
|
|
||||||
'membership',
|
|
||||||
'mine',
|
|
||||||
{
|
|
||||||
environment: stripeEnvironment,
|
|
||||||
},
|
|
||||||
'post'
|
|
||||||
);
|
|
||||||
|
|
||||||
let savedMemberships = [];
|
|
||||||
let highestMembershipRanking;
|
let highestMembershipRanking;
|
||||||
|
|
||||||
// TODO: this will work for now, but it should be adjusted
|
if (user.odysee_member) {
|
||||||
// TODO: to check if it's active, or if it's cancelled if it's still valid past current date
|
// get memberships for a given user
|
||||||
// loop through all memberships and save the @odysee ones
|
// TODO: in the future, can we specify this just to @odysee?
|
||||||
// maybe in the future we can only hit @odysee in the API call
|
|
||||||
for (const membership of response) {
|
|
||||||
if (membership.MembershipDetails && membership.MembershipDetails.channel_name === '@odysee') {
|
|
||||||
savedMemberships.push(membership.MembershipDetails.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// determine highest ranking membership based on returned data
|
const response = await Lbryio.call(
|
||||||
// note: this is from an odd state in the API where a user can be both premium/Premium + at the same time
|
'membership',
|
||||||
// I expect this can change once upgrade/downgrade is implemented
|
'mine',
|
||||||
if (savedMemberships.length > 0) {
|
{
|
||||||
// if premium plus is a membership, return that, otherwise it's only premium
|
environment: stripeEnvironment,
|
||||||
const premiumPlusExists = savedMemberships.includes('Premium+');
|
},
|
||||||
if (premiumPlusExists) {
|
'post'
|
||||||
highestMembershipRanking = 'Premium+';
|
);
|
||||||
} else {
|
|
||||||
highestMembershipRanking = 'Premium';
|
let savedMemberships = [];
|
||||||
|
|
||||||
|
// TODO: this will work for now, but it should be adjusted
|
||||||
|
// TODO: to check if it's active, or if it's cancelled if it's still valid past current date
|
||||||
|
// loop through all memberships and save the @odysee ones
|
||||||
|
// maybe in the future we can only hit @odysee in the API call
|
||||||
|
for (const membership of response) {
|
||||||
|
if (membership.MembershipDetails && membership.MembershipDetails.channel_name === '@odysee') {
|
||||||
|
savedMemberships.push(membership.MembershipDetails.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// determine highest ranking membership based on returned data
|
||||||
|
// note: this is from an odd state in the API where a user can be both premium/Premium + at the same time
|
||||||
|
// I expect this can change once upgrade/downgrade is implemented
|
||||||
|
if (savedMemberships.length > 0) {
|
||||||
|
// if premium plus is a membership, return that, otherwise it's only premium
|
||||||
|
const premiumPlusExists = savedMemberships.includes('Premium+');
|
||||||
|
if (premiumPlusExists) {
|
||||||
|
highestMembershipRanking = 'Premium+';
|
||||||
|
} else {
|
||||||
|
highestMembershipRanking = 'Premium';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,10 +185,7 @@ export function doAuthenticate(
|
||||||
data: { user, accessToken: token },
|
data: { user, accessToken: token },
|
||||||
});
|
});
|
||||||
|
|
||||||
// if user is an Odysee member, get the membership details
|
dispatch(doCheckUserOdyseeMemberships(user));
|
||||||
if (user.odysee_member) {
|
|
||||||
dispatch(doCheckUserOdyseeMemberships(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shareUsageData) {
|
if (shareUsageData) {
|
||||||
dispatch(doRewardList());
|
dispatch(doRewardList());
|
||||||
|
@ -218,11 +218,7 @@ export function doUserFetch() {
|
||||||
|
|
||||||
Lbryio.getCurrentUser()
|
Lbryio.getCurrentUser()
|
||||||
.then((user) => {
|
.then((user) => {
|
||||||
// get user membership status
|
dispatch(doCheckUserOdyseeMemberships(user));
|
||||||
if (user.odysee_member) {
|
|
||||||
dispatch(doCheckUserOdyseeMemberships(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.USER_FETCH_SUCCESS,
|
type: ACTIONS.USER_FETCH_SUCCESS,
|
||||||
data: { user },
|
data: { user },
|
||||||
|
@ -243,14 +239,10 @@ export function doUserCheckEmailVerified() {
|
||||||
// This will happen in the background so we don't need loading booleans
|
// This will happen in the background so we don't need loading booleans
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
Lbryio.getCurrentUser().then((user) => {
|
Lbryio.getCurrentUser().then((user) => {
|
||||||
|
dispatch(doCheckUserOdyseeMemberships(user));
|
||||||
|
|
||||||
if (user.has_verified_email) {
|
if (user.has_verified_email) {
|
||||||
// check premium membership
|
|
||||||
if (user.odysee_member) {
|
|
||||||
dispatch(doCheckUserOdyseeMemberships(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
dispatch(doRewardList());
|
dispatch(doRewardList());
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.USER_FETCH_SUCCESS,
|
type: ACTIONS.USER_FETCH_SUCCESS,
|
||||||
data: { user },
|
data: { user },
|
||||||
|
|
Loading…
Reference in a new issue