-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(adapter-nextjs): add createAuthRouteHandlers to createServerRunner #13801
base: hui/feat/adapter-nextjs/apply-cookie-attrs
Are you sure you want to change the base?
feat(adapter-nextjs): add createAuthRouteHandlers to createServerRunner #13801
Conversation
f934d7a
to
8e12c20
Compare
afba807
to
25c4eaa
Compare
6cbdad1
to
af39e86
Compare
25c4eaa
to
26ec9ed
Compare
af39e86
to
fa5d86c
Compare
26ec9ed
to
67d073f
Compare
// The `query` property is a convenience method added to the underlying `IncomingMessage`. | ||
return ( | ||
'query' in request && | ||
Object.prototype.toString.call(request.query) === '[object Object]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason to deviate from the typesafe object check on 22-23?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Unit tests are thorough.
config: resourcesConfig, | ||
runtimeOptions = {}, | ||
}: CreateAuthRouteHandlersFactoryInput): CreateAuthRouteHandlers => { | ||
const origin = process.env.AMPLIFY_APP_ORIGIN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider adding this as an input param in order to keep this function pure?
Cognito: { | ||
loginWith: { oauth: oAuthConfig }, | ||
}, | ||
} = resourcesConfig.Auth; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might just be me, but nested destructuring assignment beyond the first level is hard to read 😵💫
const {
Cognito: {
loginWith: { oauth: oAuthConfig },
},
} = resourcesConfig.Auth;
vs.
const { oauth: oAuthConfig } = resourcesConfig.Auth.Cognito.loginWith;
['sign-up', true], | ||
['sign-out', true], | ||
['sign-out-callback', true], | ||
['fancy-route', false], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧐🎩
path?: string, | ||
): path is SupportedRoutePaths { | ||
return ( | ||
path !== undefined && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe you don't even need this check since undefined
wouldn't be included in supported paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ts doesn't like supportedRoutePaths.includes(undefined)
as undefined
is a not allow element type in SupportedRoutePaths
@@ -0,0 +1,53 @@ | |||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe these should be called predicates since they don't actually assert?
export function isAuthRoutesHandlersContext( | ||
context: object, | ||
): context is AuthRoutesHandlerContext { | ||
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do some of these have such exhaustive checks but others don't? This check might technically allow for arrays, which is not what we want?
*/ | ||
customState?: string; | ||
/** | ||
* The app route redirect to when a sign-in flow completes. Defaults o the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
* The app route redirect to when a sign-in flow completes. Defaults o the | |
* The app route redirect to when a sign-in flow completes. Defaults to the |
*/ | ||
redirectOnSignInComplete?: string; | ||
/** | ||
* The app route redirect to when a sign-out flow completes. Defaults o the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
* The app route redirect to when a sign-out flow completes. Defaults o the | |
* The app route redirect to when a sign-out flow completes. Defaults to the |
* The handler function for handling the GET requests sent to the Auth API routes. | ||
* Only `GET` method gets handled, otherwise it rejects. | ||
* | ||
* @param request - `request` can be he following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
* @param request - `request` can be he following: | |
* @param request - `request` can be the following: |
import { isSupportedAuthApiRoutePath } from '../../../src/auth/utils/isSupportedAuthApiRoutePath'; | ||
|
||
describe('isSupportedAuthApiRoutePath', () => { | ||
test.each([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Do you need/want to test for the undefined case?
const mockEnd = jest.fn(); | ||
const mockStatus = jest.fn(() => ({ end: mockEnd })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: These look like they can be extracted and just reused with mock clears? Would help reduce some boilerplate per test to help readability
[ | ||
{ | ||
params: {}, | ||
}, | ||
false, | ||
], | ||
[ | ||
{ | ||
params: { | ||
slug: 'sign-in', | ||
}, | ||
}, | ||
true, | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could these really not fit on single lines? This is kinda rough to read
Description of changes
Issue #, if available
Description of how you validated changes
Checklist
yarn test
passesChecklist for repo maintainers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.