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

chore(adapter-nextjs): update tsdoc of the public APIs #14187

Open
wants to merge 2 commits into
base: feat/server-auth/main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions packages/adapter-nextjs/src/types/NextServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,85 @@ export declare namespace NextServer {
}

export interface CreateServerRunnerOutput {
/**
* The function to run an operation with the Amplify server context. The operation is a callback function that
* takes a context spec parameter which is used to call the Amplify-side server APIs. The result of the operation
* is returned as a promise.
*
* @example
* ```
* // In `src/amplifyUtils.ts`
* import { createServerRunner } from 'aws-amplify/adapter-nextjs';
* import outputs from '@/amplify_outputs.json';
*
* export const { runWithAmplifyServerContext } = createServerRunner({ config: outputs });
*
* // In `src/app/home/page.tsx` (App router)
* import { cookies } from 'next/headers';
* import { runWithAmplifyServerContext } from '@/amplifyUtils';
*
* export default async function HomePage() {
* const user = await runWithAmplifyServerContext({
* nextServerContext: { cookies },
* operation: (contextSpec) => getCurrentUser(contextSpec),
* });
*
* return <div>{`Hello, ${user.username}`}</div>;
* }
*
* // In `src/pages/home/index.tsx` (Pages router)
* import { runWithAmplifyServerContext } from '@/amplifyUtils';
*
* export const getServerSideProps = async ({ req, res }) => {
* const user = await runWithAmplifyServerContext({
* nextServerContext: { request: req, response: res },
* operation: (contextSpec) => getCurrentUser(contextSpec),
* });
*
* return {
* props: { user },
* }
* }
*
* export default function HomePage(props) {
* return <div>{`Hello, ${props.user.username}`}</div>;
* }
* ```
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add an @example or two for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, added.

runWithAmplifyServerContext: RunOperationWithContext;
/**
* The factory function to create the route handlers for the Amplify server-side authentication. You can call this
* function and export the result as the route handlers in the Next.js API routes, to authenticate your end users
* on the server side.
*
* Note: when enabling server-side authentication, Amplify APIs can no longer be used in the client-side.
* @experimental
*
* @example
* ```
* // In `src/amplifyUtils.ts`
* import { createServerRunner } from 'aws-amplify/adapter-nextjs';
* import outputs from '@/amplify_outputs.json';
*
* export const { createAuthRouteHandlers } = createServerRunner({ config: outputs });
*
* // In `src/app/api/auth/[slug]/route.tsx` (App router)
* import { createAuthRouteHandlers } from '@/amplifyUtils';
*
* export const GET = createAuthRouteHandlers({
* redirectOnSignInComplete: "/home",
* redirectOnSignOutComplete: "/sign-in",
* );
*
* // In `src/pages/api/auth/[slug].tsx` (Pages router)
* import { createAuthRouteHandlers } from '@/amplifyUtils';
*
* export default createAuthRouteHandlers({
* redirectOnSignInComplete: "/home",
* redirectOnSignOutComplete: "/sign-in",
* });
* ```
*/
createAuthRouteHandlers: CreateAuthRouteHandlers;
}

Expand Down
Loading