#✅ - ERROR Error logging out user: (0 , __vite_ssr_import_3__.useNuxtApp)(...).$Amplify.Auth....

3 messages · Page 1 of 1 (latest)

sharp shoal
#

I just simply followed the instruction for configuring AWS-AMPLIFY for SSR in Nuxt in the document, and everything works except when I tried to use signOut. I get the error above.

  fetchAuthSession,
  fetchUserAttributes,
  signIn,
  signUp,
  signOut,
  confirmSignUp,
  confirmSignIn,
  confirmResetPassword,
  getCurrentUser,
  resendSignUpCode,
} from 'aws-amplify/auth'
import { generateClient } from 'aws-amplify/data'
import outputs from '@/amplify_outputs.json'
import type { Schema } from '@/amplify/data/resource'
import { Amplify } from 'aws-amplify'

// configure the Amplify client library
if (import.meta.client) {
  Amplify.configure(outputs, { ssr: true })
}

// generate your data client using the Schema from your backend
const client = generateClient<Schema>()

export default defineNuxtPlugin({
  name: 'AmplifyAPIs',
  enforce: 'pre',
  setup() {
    return {
      provide: {
        // You can call the API by via the composable `useNuxtApp()`. For example:
        // `useNuxtApp().$Amplify.Auth.fetchAuthSession()`
        Amplify: {
          Auth: {
            fetchAuthSession,
            fetchUserAttributes,
            getCurrentUser,
            confirmSignUp,
            confirmSignIn,
            confirmResetPassword,
            resendSignUpCode,
            signIn,
            signOut,
            signUp,
          },
          GraphQL: {
            client,
          },
        },
      },
    }
  },
})
#

Nevermind. I accidentally called it in the middleware inside if(import.meta.server){} condition

soft lindenBOT
#

✅ - ERROR Error logging out user: (0 , vite_ssr_import_3.useNuxtApp)(...).$Amplify.Auth....