Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restricted Registration per Domain #712

Open
mamo2021 opened this issue Sep 29, 2023 · 2 comments
Open

Restricted Registration per Domain #712

mamo2021 opened this issue Sep 29, 2023 · 2 comments

Comments

@mamo2021
Copy link

Is it possible or can you make it possible that registration is only allowed for users with certain email addresses (domains)?
It is useful to restrict registration so that not everyone can use the service. However, within an organization everyone should be able to create a user account and use the service.

@poeti8
Copy link
Member

poeti8 commented Oct 19, 2023

Not right now, you can temporarily enable signup, allow some users to sign up and then disable the signup option again.

@kengher
Copy link

kengher commented Mar 12, 2024

Pretty simple but you'll have make slight edits to the code. I did it for my org and works like a charm.

  1. Open .env file, add this line somewhere:
    #add a domain var here to limit so don't have to make changes to code when it needs to be modified. LIMIT_EMAIL_DOMAIN=youremaildomain.com

  2. In client/const/site-theme.ts add:
    export const LIMIT_EMAIL_DOMAIN = publicRuntimeConfig.LIMIT_EMAIL_DOMAIN; //get var from .env file

  3. in client/pages/login.tsx:

import { LIMIT_EMAIL_DOMAIN } from "../consts/site-theme";
...
function onSubmit(type: "login" | "signup") {
    return async e => {
....
    const { email, password } = formState.values;
    const emailRegex = LIMIT_EMAIL_DOMAIN != "" ? new RegExp("^[A-Za-z][A-Za-z0-9._%+-]+@" + LIMIT_EMAIL_DOMAIN + "$", "g") : null;
...
    if (!email) {
        return setError("Email address must not be empty.");
    }
    
    if (LIMIT_EMAIL_DOMAIN != "" && !emailRegex.test(email)) { //if domain exists and doesn't match the regex then error out
        return setError("Cannot use the provided email address.");
    }
...

npm run build

This only works for one domain, but you can always code it to make it comma separated, etc.. for multiple domains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants