-
Notifications
You must be signed in to change notification settings - Fork 117
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
feature(serializer) Adding request and refactor #136
base: master
Are you sure you want to change the base?
Conversation
1fb8611
to
b869b01
Compare
Hi @boenrobot -- what about the response context? For example, if there is a session, handled by passport, and it needs to be destroyed, or there needs to be a response redirect ... without both req and res context, we may still be unable to handle all auth use cases. |
All of those cases would require an extension of the AuthGuard, not the serialization/deserialization. The serialization/deserialization should just fail if the session/jwt is invalid, but the actual error handling and recovery is in the guard. |
5a8189d
to
ae7aab0
Compare
Passport has an undocumented feature, where the request can be passed to the serializeUser/deserializeUser callback as the first argument, and whether it is or not is determined by the arguments in the function (if it accepts 3, the first is the request). This feature is used to get and pass the request to the callback. The done callback is removed in favor of a promise being expected. A rejected promise (or an exception thrown within the handler) will be passed to passport as an error. Also added types for everything as generics, defaulting to the type safe "unknown" instead of "any", allowing extenders to enforce type safety on this lower level, instead of just theirs.
ae7aab0
to
869b036
Compare
…alizer-refactor # Conflicts: # lib/passport/passport.serializer.ts
…alizer-refactor
…alizer-refactor
…alizer-refactor
@boenrobot what do you mean that it should be handled in the I can't seem to wrap my head around how to call |
Passport has an undocumented feature, where the request can be passed to the serializeUser/deserializeUser callback as the first argument, and whether it is or not is determined by the arguments in the function (if it accepts 3, the first is the request). This feature is used to get and pass the request to the callback.
The done callback is removed in favor of a promise being expected. A rejected promise (or an exception thrown within the handler) will be passed to passport as an error.
Also added types for everything as generics, defaulting to the type safe "unknown" instead of "any", allowing extenders to enforce type safety on this lower level, instead of just theirs.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
There is no way to get the request into a serialize/deserialize handler, and the handler has to specify the types of the
done
callback and call it.Issue Number: N/A
What is the new behavior?
The second argument is now the request, instead of the
done
callback. The handler is expected to return a promise, the value of which will be given to thedone
callback. If the promise is rejected, or an exception is thrown, that will be given as the error to thedone
callback.Does this PR introduce a breaking change?
Handlers will have to be changed into async functions that return the value instead of calling
done
with it. Any possible errors that they may have given todone
must instead be thrown.Serializers that don't need the request should be able to omit it from the implementation (since it's an optional second argument).
This change is trivial, but required non the less.
Other information
I've also made passport/www.passportjs.org#83 to document this feature.