appwrite/sdk-for-python

While creating team the logged in user is not getting registered as owner.

pratik-dani opened this issue · 9 comments

I have followed your documentation to the tee. I am using flask as my primary framework. In my python itself, I am creating a team for the currently logged-in user, but the logged-in user is not getting added as owner in the database.

Hey @devildani, please share some of your code. How do you connect to the Appwrite API? Using an API key you act as an app or admin you can't make actions on behalf of the user. This will be available when we'll introduce JWT authentication in upcoming v0.8 of Appwrite.

Hi. https://github.com/devildani/appwrite-flask-test. You can see my entire codebase here. I am using the API key to create a team.

@devildani as mentioned before, when you create a team using an API key, no user will be assigned as admin, because your'e not on a user scope. That said, you can use the createMembership endpoint to assign a user to that new team.

Okay, got it. But is there any way to get in the user scope with python. I did try with the JS version it works great. Is there any way inside python? Or is it something that will be coming in the future?

In the upcoming release of Appwrite (v0.8) we will introduce JWT authentication. This will allow you to use the JWT instead of the API key to authenticate in your Python code. Using the new authentication method you will be able to preform actions of behalf of your user in your server side just like you're doing on your client side right now.

I see that you have now released v0.8. So, I have a few questions. The JWT will be different for each user right? If, so your documentation says I should initialize it at the start instead of using it on the user to user basis.

Also, while calling your CDN for appwrite <script src="https://cdn.jsdelivr.net/npm/appwrite@3.0.5"></script>, it is giving an error: Uncaught TypeError: Appwrite is not a constructor. Is there something that I am doing wrong?

When implementing using a CDN just use: var appwrite = new Appwrite.Appwrite();, this is actually not the desired behavior or the way the docs describe the init code for the Web SDK, and we'll most likely release a fix by tomorrow (@TorstenDittmann).

For the JWT, yes. The JWT is individual for every user. You should re-init the SDK for every user or create a new instance of it (it has zero-cost, no HTTP calls are executed on init)

Ok. I can re-init the SDK for every user. But that is not a good method right? I know it will work but there should be a better way for doing this. Right?

Also, what if someone is using flask (python) as its client-side, but there is no implementation of getting the JWT token on the python side. Why not let us generate a JWT token on the python side?

The Appwrite JWT is designed to allow you to act on behalf of your client-side user (web, flutter, ios, android) in your server in an easy way. You generate the token in the client side, pass it to the server (python/flask, node/express, php/laravel) and their you can do any actions you wish on behalf of that user which is not possible using an API key, where you only have an app scope.

What kind of use-case you had in mind?