Trying to build an AWS Amplify app using VueJS.
amplify add auth
amplify push
amplify env pull dev
I added an Auth module, authentication works based on an example using the authenticator
tag
import { Authenticator } from "@aws-amplify/ui-vue";
<authenticator>
<template v-slot="{ user, signOut }">
...
I'm trying to get the OAuth user token to call other services, I recall there was an object Auth, which provided as well some methods getting the user details
Howevere when following some guides
import { Auth } from 'aws-amplify';
The application fails to display and the browser logs an exception:
App.vue:4 Uncaught SyntaxError: The requested module '/node_modules/.vite/deps/aws-amplify.js?v=ec6e723f' does not provide an export named 'Auth' (at App.vue:4:10)
How do I get the Auth object .. or the OAuth token?
Edit:
amplify --version: 12.8.2
"aws-amplify": "^6.0.5"
I managed to get the access_token, yet I'm not sure if this is the correct/best approach
import { fetchAuthSession } from 'aws-amplify/auth;
onMounted( async() => {
try {
console.log("AUTH: "+ JSON.stringify(await fetchAuthSession() ));
} catch(err) {
console.error(err);
} })
I found the answer on the Amplify API documentation: https://docs.amplify.aws/vue/build-a-backend/restapi/customize-authz/
import { fetchAuthSession } from 'aws-amplify/auth'
...
const authToken = (await fetchAuthSession()).tokens?.idToken?.toString();