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

Usage with koa #93

Open
timbru31 opened this issue Aug 16, 2015 · 4 comments
Open

Usage with koa #93

timbru31 opened this issue Aug 16, 2015 · 4 comments
Labels

Comments

@timbru31
Copy link

Hi,

I'm currently trying to use passport-local-mongoose with koa, but my code doesn't seem to work.
Any hint what I'm doing wrong? Or is koa just not (yet) supported?

Snippet. (registers a new user, when the Account is created successfully redirect to the index page, if not display error)

router.post('/admin/register', function* () {
  Account.register(new Account({
    username : this.request.body.username
  }),
  this.request.body.password, function*(err, account) {
    console.log(ctx);
    if (err) {
      yield this.render('admin/register', {
        error : err
      });
    } else {
      yield this.render('admin/index', {
        acc : account.username
      });
    }
 });
});

Thanks in advance.
(Code worked in express just fine)

@timbru31
Copy link
Author

timbru31 commented Sep 2, 2015

@saintedlama No response so far? ❓

@saintedlama
Copy link
Owner

Sorry, I've really not enough experience with koa to help you with the issue.
Passport-local-mongoose is not tested with koa and since you have an issue I guess we do not support koa

@spisovatelprogramu
Copy link

There is an example with Promise:

router.post('/register', async(ctx, next) => {
  let user = new UserModel(ctx.request.body);

  return await new Promise(function (resolve, reject) {
    UserModel.register(user, ctx.request.body.password, (err, user) => {
      if (err) {
        reject(err);
      }

      ctx.state.user = user.toObject();
      return resolve(next());
    });
  });
});

@niftylettuce
Copy link
Contributor

We've added complete, in-depth Koa (v2+) support using passport-local-mongoose. We wrote some extra glue to handle edge cases as well, and added an async register function.

https://lad.js.org

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

No branches or pull requests

4 participants