You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DioError [DioErrorType.RESPONSE]: Http status error [401], but I am authorized #801
Hello, I have some problem with create a document on appwrite (flutter web), when I start the process for creation, I have an error: DioError [DioErrorType.RESPONSE]: Http status error [401].
But I am authorized.
And I can read a document from appwrite, but I can't create a document to appwrite
Thats a part of code of creation document:
{"$id":"5ff46a34a631f","type":1,"expire":1641389492}
[GETX] "GetMaterialController" has been initialized
[GETX] GOING TO ROUTE /home
[GETX] "HomeController" has been initialized
DioError [DioErrorType.RESPONSE]: Http status error [401]
false
When I want read document from appwrite, I can do it, but when I want to create document to appwrite, I can't do it. What I need to do? Create session is success but I can' to write.
Are you able to fetch your user account? you can only write the document after creating a user account + login (creating a user session). If you can't get the user account your session might have been deleted or expired.
I can't get session, because I get the same error
[GETX] "GetMaterialController" has been initialized
[GETX] GOING TO ROUTE /home
[GETX] "HomeController" has been initialized
{"$id":"5ff48213a6a04","type":1,"expire":1641395603} - init client()
DioError [DioErrorType.RESPONSE]: Http status error [401] - getSession
DioError [DioErrorType.RESPONSE]: Http status error [401] - try to create document
@klnfreedom sorry for all the questions, but I just want to be sure I understand the problem scope. This error happens to you only on web or web+ios+android?
Activity
eldadfux commentedon Jan 5, 2021
Before creating documents you need to authenticate your user by creating an account, and then an account session.
klnfreedom commentedon Jan 5, 2021
{"$id":"5ff46a34a631f","type":1,"expire":1641389492}
[GETX] "GetMaterialController" has been initialized
[GETX] GOING TO ROUTE /home
[GETX] "HomeController" has been initialized
DioError [DioErrorType.RESPONSE]: Http status error [401]
false
I made it, but not working, how can I fix it?
klnfreedom commentedon Jan 5, 2021
The same error
klnfreedom commentedon Jan 5, 2021
I'm authenticated, but the same error
eldadfux commentedon Jan 5, 2021
Make sure your collection has write permissions for that user,
*can be a good value for testingklnfreedom commentedon Jan 5, 2021
When I want to create document, I need to take json code from collection or from the document?
eldadfux commentedon Jan 5, 2021
@klnfreedom not sure I understand the question. Do you have a wildcard permission in your collection settings?
klnfreedom commentedon Jan 5, 2021
Yes, I have a wildcard permission in write access and read accsess too
klnfreedom commentedon Jan 5, 2021
klnfreedom commentedon Jan 5, 2021
Is it a right json code for creating document?
class Autogenerated {
String id;
String collection;
Permissions permissions;
String date;
Autogenerated({this.id, this.collection, this.permissions, this.date});
Autogenerated.fromJson(Map<String, dynamic> json) {
id = json['$id'];
collection = json['$collection'];
permissions = json['$permissions'] != null
? new Permissions.fromJson(json['$permissions'])
: null;
date = json['Date'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['Date'] = this.date;
return data;
}
}
class Permissions {
List read;
List write;
Permissions({this.read, this.write});
Permissions.fromJson(Map<String, dynamic> json) {
read = json['read'].cast();
write = json['write'].cast();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['read'] = this.read;
data['write'] = this.write;
return data;
}
}
klnfreedom commentedon Jan 5, 2021
When I want read document from appwrite, I can do it, but when I want to create document to appwrite, I can't do it. What I need to do? Create session is success but I can' to write.
klnfreedom commentedon Jan 5, 2021
try {
Response response = await database.createDocument(
collectionId: AppConstants.collection,
data: data.toJson(),
read: [""],
write: [""],
);
print(response);
return true;
} catch (e) {
print(e);
return false;
}
}
It's a part of my code for creating
klnfreedom commentedon Jan 5, 2021
what am I doing wrong?
eldadfux commentedon Jan 5, 2021
Are you able to fetch your user account? you can only write the document after creating a user account + login (creating a user session). If you can't get the user account your session might have been deleted or expired.
klnfreedom commentedon Jan 5, 2021
I can't get session, because I get the same error
[GETX] "GetMaterialController" has been initialized
[GETX] GOING TO ROUTE /home
[GETX] "HomeController" has been initialized
{"$id":"5ff48213a6a04","type":1,"expire":1641395603} - init client()
DioError [DioErrorType.RESPONSE]: Http status error [401] - getSession
DioError [DioErrorType.RESPONSE]: Http status error [401] - try to create document
eldadfux commentedon Jan 6, 2021
@klnfreedom you need to use createSession not getSession
klnfreedom commentedon Jan 6, 2021
initClient it is a method which is included createSession();
It is very interesting, I can create session and I get id of client, but when I want to getSession, I give DioException Http 401
And when I want to create document I get the same problem
eldadfux commentedon Jan 7, 2021
@klnfreedom are you testing this on Flutter Web?
klnfreedom commentedon Jan 7, 2021
Yes, I tested, but I have the same error
eldadfux commentedon Jan 7, 2021
@klnfreedom sorry for all the questions, but I just want to be sure I understand the problem scope. This error happens to you only on web or web+ios+android?
klnfreedom commentedon Jan 8, 2021
Everythhing is cool, thank you for your support
Macdeo commentedon Jan 16, 2021
How did you fixed this issue @klnfreedom
klnfreedom commentedon Jan 16, 2021
appwrite/sdk-for-flutter#5
Macdeo commentedon Jan 16, 2021
Thanks
lohanidamodar commentedon Jan 20, 2021
I think it's safe to close this issue as it is for now resolved by
appwrite/sdk-for-flutter#5
Feel free to reopen if it is not resolved for you, or continue discussion in appwrite/sdk-for-flutter#5.