mobilizon.chapril.org-mobil.../js/src/router/guards/register-guard.ts
Thomas Citharel d552fcb2d3
Add a config option to whitelist users registration
Through whole email or domain email

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2019-12-17 12:09:24 +01:00

24 lines
710 B
TypeScript

import { apolloProvider } from '@/vue-apollo';
import { CONFIG } from '@/graphql/config';
import { IConfig } from '@/types/config.model';
import { NavigationGuard } from 'vue-router';
import { ErrorRouteName } from '@/router/error';
import { ErrorCode } from '@/types/error-code.model';
export const beforeRegisterGuard: NavigationGuard = async function (to, from, next) {
const { data } = await apolloProvider.defaultClient.query({
query: CONFIG,
});
const config: IConfig = data.config;
if (!config.registrationsOpen && !config.registrationsWhitelist) {
return next({
name: ErrorRouteName.ERROR,
query: { code: ErrorCode.REGISTRATION_CLOSED },
});
}
return next();
};