Redirect users without license to coupon page
This commit is contained in:
parent
26a342c5a5
commit
f3bd38e819
|
|
@ -7,6 +7,7 @@ fragment UserParts on UserNode {
|
|||
firstName
|
||||
lastName
|
||||
avatarUrl
|
||||
licenseExpiryDate
|
||||
lastModule {
|
||||
id
|
||||
slug
|
||||
|
|
|
|||
|
|
@ -134,6 +134,12 @@ function unauthorizedAccess(to) {
|
|||
return loginRequired(to) && getCookieValue('loginStatus') !== 'true';
|
||||
}
|
||||
|
||||
function redirectUsersWithoutValidLicense(to) {
|
||||
return privateApolloClient.query({
|
||||
query: ME_QUERY,
|
||||
}).then(({data}) => data.me.licenseExpiryDate.edges.length == null);
|
||||
}
|
||||
|
||||
function redirectStudentsWithoutClass() {
|
||||
return privateApolloClient.query({
|
||||
query: ME_QUERY,
|
||||
|
|
@ -147,7 +153,6 @@ function networkErrorCallback(statusCode) {
|
|||
}
|
||||
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
// handle logout
|
||||
if (to.path === '/logout') {
|
||||
privateApolloClient.resetStore();
|
||||
next({name: 'login'});
|
||||
|
|
@ -160,6 +165,12 @@ router.beforeEach(async (to, from, next) => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (to.name !== 'licenseActivation' && redirectUsersWithoutValidLicense()) {
|
||||
next({name: 'licenseActivation'})
|
||||
return;
|
||||
}
|
||||
|
||||
// handle users students without class
|
||||
if ((to.name !== 'noClass' && to.name !== 'licenseActivation') && loginRequired(to) && await redirectStudentsWithoutClass()) {
|
||||
next({name: 'noClass'})
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class UserNode(DjangoObjectType):
|
|||
model = User
|
||||
filter_fields = ['username', 'email']
|
||||
only_fields = ['username', 'email', 'first_name', 'last_name', 'school_classes', 'last_module', 'avatar_url',
|
||||
'selected_class']
|
||||
'selected_class', 'license_expiry_date']
|
||||
interfaces = (relay.Node,)
|
||||
|
||||
def resolve_pk(self, info, **kwargs):
|
||||
|
|
|
|||
Loading…
Reference in New Issue