E
E
Emptyform2016-10-06 17:05:02
Node.js
Emptyform, 2016-10-06 17:05:02

How to login a newly registered user?

Hey!
I use koa , koa-generic-session , koa-passport , passport-local .
The user enters the registration form, enters data, submits. The node registers the user in the database (login, password hash, salt, ...). Further throws on the login form.
How to make sure that after registering a user in the database, he does not need to go to the login form and register his session, but so that the user session is immediately registered when the user is saved to the database?
update: You can, of course, take a koa-request and send the completed login form to yourself, but surely you can do it without crutches?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Emptyform, 2016-10-06
@Emptyform

As usual, everything is simple:

const passport = require('koa-passport');
...
yield passport.authenticate('local', {
    successRedirect: '/',
    failureRedirect: '/'
});
...

BUT!
This only works because the fields in the registration form have exactly the same name and id as in the login form, and at the time of calling authenticate , this.request.body contains data about these fields passed from the registration form, so the authentication is successful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question