AppWrite -JWT不允许访问文档
当用户在前端登录时,我无法使用创建的JWT向后端提出请求。
每次尝试尝试,即使对集合的访问设置为角色:所有,我都会从后端获得此错误:
{
"statusCode": 500,
"code": "401",
"error": "Internal Server Error",
"message": "<User> (role: member) missing scope (collections.read)"
}
我正在使用appwrite node sdk用于服务器part和appwrite web sdk在前端。
这是我生成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
},
}
}
我缺少什么?
注意:我正在运行Docker容器中的所有内容。
I'm unable to make a request to my backend using a JWT created when the user logs in in the frontend.
Everytime I try, even if the access to the collection is set to role:all, I get this error from the backend:
{
"statusCode": 500,
"code": "401",
"error": "Internal Server Error",
"message": "<User> (role: member) missing scope (collections.read)"
}
I'm using Appwrite Node SDK for server part and Appwrite web sdk in the frontend.
This is my login script where I generate the JWT token:
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
},
}
}
What am I missing?
Note: I am running everything inside Docker containers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此错误表明您正在尝试获取收集,而不是收集中的文档。确保您正在使用
databases.listDocuments()
。注意:此示例代码使用Node-AppWrite版本7.0.2,用于AppWrite版本0.15.x。
This error indicates you're trying to fetch a collection rather than documents in your collection. Make sure you're using
databases.listDocuments()
.Note: this sample code uses node-appwrite version 7.0.2 and is meant for Appwrite version 0.15.X.