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

Upgraded to 1.4.0, but it seems like next()/response.send() isn't called within the passport example #49

Closed
zoubarevm opened this issue Mar 19, 2017 · 2 comments
Assignees
Labels

Comments

@zoubarevm
Copy link

zoubarevm commented Mar 19, 2017

Hey!

I'm not entirely sure why, but it seems like the following method never really triggers the next()/ response.send() functions (even though it's returned as a promise) and the server hangs when I call login using 1.4.0.

Let me know if you have any ideas on where I could look to resolve this.

Cheers!

/**
     * Authenticate user with local info (in Database).
     * @param email
     * @param password
     * @param request
     * @param response
     * @param next
     */
    @Post('/login')
    public login(
        @Required() @BodyParams('email') email: string,
        @Required() @BodyParams('password') password: string,
        @Request() request: Express.Request,
        @Response() response: Express.Response,
        @Next() next: Express.NextFunction
    ) {
        console.log('resquest.cookies', request.cookies);

        return new Promise<IUser>((resolve, reject) => {

            try{
                Passport
                    .authenticate('login', (err, user: IUser) => {

                        if (err) {
                            reject(err);
                        }

                        request.logIn(user, (err) => {

                            if (err) {
                                reject(err);
                            }

                            resolve(user);
                        });

                    })(request, response, next);
            }catch (er){
                console.error(er);
            }
        })
            .catch((err) => {

                if(err && err.message === "Failed to serialize user into session") {
                    throw new NotFound('user not found');
                }

                return Promise.reject(err);
            });

    }

EDIT

Adding something like following after the promise creation seems to resolve this:

...
         .then(x => {
            response.send(x);
            next();
        })
...
@zoubarevm zoubarevm changed the title Upgraded to 1.4.0, but it seems like next() isn't called within the passport example Upgraded to 1.4.0, but it seems like next()/response.send() isn't called within the passport example Mar 19, 2017
@Romakita
Copy link
Collaborator

Romakita commented Mar 19, 2017

Hi @zoubarevm ,

Effectively, it's a bug about the new middleware management, when you use @Next() and return a promise at the same time.

v1.4.1 fix them :)

Thanks a lot :)

@Romakita Romakita self-assigned this Mar 19, 2017
@zoubarevm
Copy link
Author

@Romakita awesome! Just tried it and it works :)

Thanks for your help!

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

2 participants