@@ -67,8 +67,9 @@ import {
67
67
signIn ,
68
68
signOut
69
69
} from ' aws-amplify/auth' ;
70
- import { list } from ' aws-amplify/storage' ;
71
70
import { generateClient } from ' aws-amplify/api' ;
71
+ import { list } from ' aws-amplify/storage' ;
72
+
72
73
import outputs from ' ../amplify_outputs.json' ;
73
74
74
75
const client = generateClient <Schema >();
@@ -79,7 +80,7 @@ export default defineNuxtPlugin({
79
80
80
81
setup() {
81
82
// This configures Amplify on the client side of your Nuxt app
82
- Amplify .configure (config , { ssr: true });
83
+ Amplify .configure (outputs , { ssr: true });
83
84
84
85
return {
85
86
provide: {
@@ -119,27 +120,25 @@ Make sure you call `Amplify.configure` as early as possible in your application
119
120
Example implementation:
120
121
121
122
``` ts title="plugins/01.amplifyApis.server.ts"
123
+ import type { FetchAuthSessionOptions } from ' aws-amplify/auth' ;
124
+ import type { ListPaginateWithPathInput } from ' aws-amplify/storage' ;
122
125
import type { CookieRef } from ' nuxt/app' ;
123
126
import type { Schema } from ' ~/amplify/data/resource' ;
124
- import type { ListPaginateWithPathInput } from ' aws-amplify/storage' ;
125
- import type {
126
- LibraryOptions ,
127
- FetchAuthSessionOptions
128
- } from ' @aws-amplify/core' ;
127
+
129
128
import {
129
+ createAWSCredentialsAndIdentityIdProvider ,
130
130
createKeyValueStorageFromCookieStorageAdapter ,
131
131
createUserPoolsTokenProvider ,
132
- createAWSCredentialsAndIdentityIdProvider ,
133
132
runWithAmplifyServerContext
134
133
} from ' aws-amplify/adapter-core' ;
135
- import { parseAmplifyConfig } from ' aws-amplify/utils ' ;
134
+ import { generateClient } from ' aws-amplify/api/server ' ;
136
135
import {
137
136
fetchAuthSession ,
138
137
fetchUserAttributes ,
139
138
getCurrentUser
140
139
} from ' aws-amplify/auth/server' ;
141
140
import { list } from ' aws-amplify/storage/server' ;
142
- import { generateClient } from ' aws-amplify/api/server ' ;
141
+ import { parseAmplifyConfig } from ' aws-amplify/utils ' ;
143
142
144
143
import outputs from ' ../amplify_outputs.json' ;
145
144
@@ -273,7 +272,7 @@ export default defineNuxtPlugin({
273
272
);
274
273
275
274
// Create the libraryOptions object
276
- const libraryOptions: LibraryOptions = {
275
+ const libraryOptions = {
277
276
Auth: {
278
277
tokenProvider ,
279
278
credentialsProvider
@@ -423,11 +422,12 @@ Example implementation:
423
422
424
423
``` ts title="plugins/02.authRedirect.ts"
425
424
import { Amplify } from ' aws-amplify' ;
425
+
426
426
import outputs from ' ~/amplify_outputs.json' ;
427
427
428
428
// Amplify.configure() only needs to be called on the client side
429
429
if (process .client ) {
430
- Amplify .configure (config , { ssr: true });
430
+ Amplify .configure (outputs , { ssr: true });
431
431
}
432
432
433
433
export default defineNuxtPlugin ({
@@ -484,20 +484,20 @@ Example implementation:
484
484
485
485
``` ts title="utils/amplifyUtils.ts"
486
486
import type { H3Event , EventHandlerRequest } from ' h3' ;
487
+
487
488
import {
489
+ AmplifyServer ,
490
+ CookieStorage ,
491
+ createAWSCredentialsAndIdentityIdProvider ,
488
492
createKeyValueStorageFromCookieStorageAdapter ,
489
493
createUserPoolsTokenProvider ,
490
- createAWSCredentialsAndIdentityIdProvider ,
491
494
runWithAmplifyServerContext ,
492
- AmplifyServer ,
493
- CookieStorage
494
495
} from ' aws-amplify/adapter-core' ;
495
496
import { parseAmplifyConfig } from ' aws-amplify/utils' ;
496
497
497
- import type { LibraryOptions } from ' @aws-amplify/core' ;
498
498
import outputs from ' ~/amplify_outputs.json' ;
499
499
500
- const amplifyConfig = parseAmplifyConfig (config );
500
+ const amplifyConfig = parseAmplifyConfig (outputs );
501
501
502
502
const createCookieStorageAdapter = (
503
503
event : H3Event <EventHandlerRequest >
@@ -527,7 +527,7 @@ const createCookieStorageAdapter = (
527
527
528
528
const createLibraryOptions = (
529
529
event : H3Event <EventHandlerRequest >
530
- ): LibraryOptions => {
530
+ ) => {
531
531
const cookieStorage = createCookieStorageAdapter (event );
532
532
const keyValueStorage =
533
533
createKeyValueStorageFromCookieStorageAdapter (cookieStorage );
@@ -571,6 +571,7 @@ Take implementing an API route `GET /api/current-user` , in `server/api/current-
571
571
572
572
``` ts title="server/api/current-user.ts"
573
573
import { getCurrentUser } from ' aws-amplify/auth/server' ;
574
+
574
575
import { runAmplifyApi } from ' ~/server/utils/amplifyUtils' ;
575
576
576
577
export default defineEventHandler (async (event ) => {
0 commit comments