尝试使用 VueJS 构建 AWS Amplify 应用程序。
amplify add auth
amplify push
amplify env pull dev
我添加了一个 Auth 模块,身份验证基于使用 authenticator
标签
的example 进行工作
import { Authenticator } from "@aws-amplify/ui-vue";
<authenticator>
<template v-slot="{ user, signOut }">
...
我正在尝试获取 OAuth 用户令牌来调用其他服务,我记得有一个对象 Auth,它还提供了一些获取用户详细信息的方法
但是遵循一些指南
import { Auth } from 'aws-amplify';
应用程序无法显示,浏览器记录异常:
App.vue:4未捕获的语法错误:请求的模块'/node_modules/.vite/deps/aws-amplify.js?v=ec6e723f'不提供名为'Auth'的导出(在App.vue:4:10)
如何获取 Auth 对象..或 OAuth 令牌?
编辑:
放大--版本:12.8.2
“aws-amplify”:“^6.0.5”
我设法获得了 access_token,但我不确定这是否是正确/最佳方法
import { fetchAuthSession } from 'aws-amplify/auth;
onMounted( async() => {
try {
console.log("AUTH: "+ JSON.stringify(await fetchAuthSession() ));
} catch(err) {
console.error(err);
} })
我在 Amplify API 文档中找到了答案: https://docs.amplify.aws/vue/build-a-backend/restapi/customize-authz/
import { fetchAuthSession } from 'aws-amplify/auth'
...
const authToken = (await fetchAuthSession()).tokens?.idToken?.toString();