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

feat(adapter-nextjs): add createAuthRouteHandlers to createServerRunner #13801

Open
wants to merge 1 commit into
base: hui/feat/adapter-nextjs/apply-cookie-attrs
Choose a base branch
from

Conversation

HuiSF
Copy link
Member

@HuiSF HuiSF commented Sep 11, 2024

Description of changes

Issue #, if available

Description of how you validated changes

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@HuiSF HuiSF force-pushed the hui/feat/adapter-nextjs/2-auth-api-handlers branch from f934d7a to 8e12c20 Compare September 11, 2024 23:49
@HuiSF HuiSF changed the title feat(aws-amplify|adapter-nextjs): add runtimeOptions.cookies to createServerRunner feat(adapter-nextjs): add createAuthRouteHandlers to createServerRunner Sep 11, 2024
@HuiSF HuiSF force-pushed the hui/feat/adapter-nextjs/2-auth-api-handlers branch 3 times, most recently from afba807 to 25c4eaa Compare September 13, 2024 01:24
@HuiSF HuiSF force-pushed the hui/feat/adapter-nextjs/apply-cookie-attrs branch from 6cbdad1 to af39e86 Compare October 1, 2024 23:01
@HuiSF HuiSF requested a review from a team as a code owner October 1, 2024 23:01
@HuiSF HuiSF force-pushed the hui/feat/adapter-nextjs/2-auth-api-handlers branch from 25c4eaa to 26ec9ed Compare October 1, 2024 23:02
@HuiSF HuiSF force-pushed the hui/feat/adapter-nextjs/apply-cookie-attrs branch from af39e86 to fa5d86c Compare November 21, 2024 17:04
@HuiSF HuiSF force-pushed the hui/feat/adapter-nextjs/2-auth-api-handlers branch from 26ec9ed to 67d073f Compare November 21, 2024 17:05
// The `query` property is a convenience method added to the underlying `IncomingMessage`.
return (
'query' in request &&
Object.prototype.toString.call(request.query) === '[object Object]'
Copy link
Member

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?

Copy link
Member

@jjarvisp jjarvisp left a 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;
Copy link
Member

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;
Copy link
Member

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],
Copy link
Member

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 &&
Copy link
Member

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

Copy link
Member Author

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.
Copy link
Member

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 (
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
* 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
* 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
* @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([
Copy link
Member

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?

Comment on lines +22 to +23
const mockEnd = jest.fn();
const mockStatus = jest.fn(() => ({ end: mockEnd }));
Copy link
Member

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

Comment on lines +16 to +29
[
{
params: {},
},
false,
],
[
{
params: {
slug: 'sign-in',
},
},
true,
],
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants