Search code examples
node.jsgoogle-apistormpath

How to allow only one user to register with Stormpath


Context: I have never work with Stormpath before and want to fully learn how to do certain stuff. To practice I'm creating my own portfolio, including the CMS.

My question is, how can I restrict the registration of accounts to a handful of specific emails using Google API (only me should be able to add and remove content from my own portfolio).

E.g. Allow ONLY [email protected] and [email protected] to register.

I could do it manually, but I do not want to do that. Steps I would like to follow are:

  1. Specify emails
  2. User tries to access the CMS
  3. User is prompted to login or register
  4. Only if user is in the specified list of emails, user can register using Google's API.

I do understand this is a very general question that involves several fields: Google's API, Stormpath, not to mention Express and Node, but maybe someone else solved this problem and I can see some code. Thanks.


Solution

  • I'm the author of the express-stormpath library which I'm assuming you're using. There's nothing out-of-the-box that does this, so I'd like to point out the best way to do this:

    Now, in the real world you probably wouldn't want to do this sort of thing (it's a lot of extra work, and doesn't buy you much). What you'd probably want to do instead is: completely disable account registration on your website. This way, only YOU can create an account using the Stormpath dashboard on https://stormpath.com, but login still works on your site so that you can log in.

    Does that make sense?

    So basically, what I'm suggesting is that you disable registration on your site by saying:

    app.use(stormpath.init(app, {
      enableRegistration: false,  // this will disable the registration page / functionality
      // ...
    }));
    

    Hopefully this helps =)