-
Notifications
You must be signed in to change notification settings - Fork 57
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
Helper function to simply check if the user is logged in #21
Comments
Hi @keokilee, Thanks for raising this issue and submitting a PR. I understand that you want to apply some custom logic to the request after authentication with Cognito is taken care of. In #20, the issue creator says:
I'm wondering if this approach would work for your use case? Regards, |
Yeah, I think that'd work. Just needed something simple to check if the user is authenticated, but being able to hook into the authentication response and add custom handling would be great as well. |
Not sure if this would make sense for a pull-request as it would constitute as breaking change to the API for anyone already doing enrichment of the I've internally forked the code at work because we have a handful of changes and can't wait around for the Pull Request / Release cycle on the library. What I've done is the following:
Add Type(s) for
|
The resulting changes to my root Lambda function look like the following: // cognito-at-edge
function authenticationHandler({ event }): Promise<HandleResponse> {
return authenticator.handle(event);
}
// Lambda@Edge Handler
export const main = async (event, context, callback) => {
const response = await authenticationHandler({ event });
if (response.isAuthenticated) {
// Add Apache-style `DocumentRoot` Functionality
documentRootHandler({ request: response.result });
// Add Access Token to Header, i.e. `X-Cf-Accesstoken` a la AWS ALB `X-Amzn-Accesstoken`
authenticationHeaderHandler({ request: response.result, tokens: response.tokens });
}
return response.result;
}; |
What would you like to be added:
Trying to grok the code and think that it's pretty awesome that you can hand off the request to this library and it takes care of authenticating the user. However, we set up Cloudfront to be on a wildcard domain, and we have logic in our Viewer Request function to inspect the
Host
header and store that in another header for our Origin Request function. What I would like is a simple function to determine if the user is authenticated or not. With that, I would know when to trigger our custom logic.Although, supporting multiple domains would be interesting. Maybe that's a separate request though.
Why is this needed:
It'll just give us some options when integrating this package with an existing viewer request function. The only other way would be to inspect the output of the
handle
function.The text was updated successfully, but these errors were encountered: