Skip to content

fix(ssr): remove mentioning of internal packages #8282

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

Merged
merged 2 commits into from
Mar 12, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ import {
signIn,
signOut
} from 'aws-amplify/auth';
import { list } from 'aws-amplify/storage';
import { generateClient } from 'aws-amplify/api';
import { list } from 'aws-amplify/storage';

import outputs from '../amplify_outputs.json';

const client = generateClient<Schema>();
Expand All @@ -79,7 +80,7 @@ export default defineNuxtPlugin({

setup() {
// This configures Amplify on the client side of your Nuxt app
Amplify.configure(config, { ssr: true });
Amplify.configure(outputs, { ssr: true });

return {
provide: {
Expand Down Expand Up @@ -119,27 +120,25 @@ Make sure you call `Amplify.configure` as early as possible in your application
Example implementation:

```ts title="plugins/01.amplifyApis.server.ts"
import type { FetchAuthSessionOptions } from 'aws-amplify/auth';
import type { ListPaginateWithPathInput } from 'aws-amplify/storage';
import type { CookieRef } from 'nuxt/app';
import type { Schema } from '~/amplify/data/resource';
import type { ListPaginateWithPathInput } from 'aws-amplify/storage';
import type {
LibraryOptions,
FetchAuthSessionOptions
} from '@aws-amplify/core';

import {
createAWSCredentialsAndIdentityIdProvider,
createKeyValueStorageFromCookieStorageAdapter,
createUserPoolsTokenProvider,
createAWSCredentialsAndIdentityIdProvider,
runWithAmplifyServerContext
} from 'aws-amplify/adapter-core';
import { parseAmplifyConfig } from 'aws-amplify/utils';
import { generateClient } from 'aws-amplify/api/server';
import {
fetchAuthSession,
fetchUserAttributes,
getCurrentUser
} from 'aws-amplify/auth/server';
import { list } from 'aws-amplify/storage/server';
import { generateClient } from 'aws-amplify/api/server';
import { parseAmplifyConfig } from 'aws-amplify/utils';

import outputs from '../amplify_outputs.json';

Expand Down Expand Up @@ -273,7 +272,7 @@ export default defineNuxtPlugin({
);

// Create the libraryOptions object
const libraryOptions: LibraryOptions = {
const libraryOptions = {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this type available from the main package?

Copy link
Member Author

Choose a reason for hiding this comment

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

@josefaidt This type is not available in the main package. In this example it's not necessary, since tokenProvider and credentialsProvider are typed individually

Auth: {
tokenProvider,
credentialsProvider
Expand Down Expand Up @@ -423,11 +422,12 @@ Example implementation:

```ts title="plugins/02.authRedirect.ts"
import { Amplify } from 'aws-amplify';

import outputs from '~/amplify_outputs.json';

// Amplify.configure() only needs to be called on the client side
if (process.client) {
Amplify.configure(config, { ssr: true });
Amplify.configure(outputs, { ssr: true });
}

export default defineNuxtPlugin({
Expand Down Expand Up @@ -484,20 +484,20 @@ Example implementation:

```ts title="utils/amplifyUtils.ts"
import type { H3Event, EventHandlerRequest } from 'h3';

import {
AmplifyServer,
CookieStorage,
createAWSCredentialsAndIdentityIdProvider,
createKeyValueStorageFromCookieStorageAdapter,
createUserPoolsTokenProvider,
createAWSCredentialsAndIdentityIdProvider,
runWithAmplifyServerContext,
AmplifyServer,
CookieStorage
} from 'aws-amplify/adapter-core';
import { parseAmplifyConfig } from 'aws-amplify/utils';

import type { LibraryOptions } from '@aws-amplify/core';
import outputs from '~/amplify_outputs.json';

const amplifyConfig = parseAmplifyConfig(config);
const amplifyConfig = parseAmplifyConfig(outputs);

const createCookieStorageAdapter = (
event: H3Event<EventHandlerRequest>
Expand Down Expand Up @@ -527,7 +527,7 @@ const createCookieStorageAdapter = (

const createLibraryOptions = (
event: H3Event<EventHandlerRequest>
): LibraryOptions => {
) => {
const cookieStorage = createCookieStorageAdapter(event);
const keyValueStorage =
createKeyValueStorageFromCookieStorageAdapter(cookieStorage);
Expand Down Expand Up @@ -571,6 +571,7 @@ Take implementing an API route `GET /api/current-user` , in `server/api/current-

```ts title="server/api/current-user.ts"
import { getCurrentUser } from 'aws-amplify/auth/server';

import { runAmplifyApi } from '~/server/utils/amplifyUtils';

export default defineEventHandler(async (event) => {
Expand Down