当用户在前端登录时,我无法使用创建的JWT向后端发出请求。
每次尝试时,即使将对集合的访问设置为role:all,我也会从后端获得此错误:
{
"statusCode": 500,
"code": "401",
"error": "Internal Server Error",
"message": "<User> (role: member) missing scope (collections.read)"
}我在服务器部分使用Appwrite,而在前端使用Appwrite。
这是我的登录脚本,我在其中生成JWT令牌:
import { Appwrite } from "appwrite";
export const login = async (email, password) => {
const api = new Appwrite();
api.setEndpoint(import.meta.env.VITE_APPWRITE_URL);
api.setProject(import.meta.env.VITE_APPWRITE_PROJECT);
await api.account.createSession(email, password);
const user = await api.account.get();
const jwt = await api.account.createJWT();
return {
jwt: jwt.jwt,
user: {
id: user.$id,
email: user.email,
name: user.name
},
}
}我遗漏了什么?
注意:我正在码头集装箱内运行所有的设备。
发布于 2022-07-08 22:05:31
(角色:成员)缺失范围(collections.read)
此错误表示您试图在集合中获取集合而不是文档。确保您使用的是databases.listDocuments()。
const sdk = require('node-appwrite');
// Init SDK
const client = new sdk.Client();
const databases = new sdk.Databases(client, '[DATABASE_ID]');
client
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
.setJWT('919c2d18fb5d4...a2ae413da83346ad2') // Your JWT token
;
const promise = databases.listDocuments('[COLLECTION_ID]');
promise.then(function (response) {
console.log(response);
}, function (error) {
console.log(error);
});注意:此示例代码使用节点- Appwrite版本7.0.2,用于AppWriteVersion0.15.x。
https://stackoverflow.com/questions/72631265
复制相似问题