authx
authx copied to clipboard
MongoDBBackend has no attribute client
First Check
- [X] I added a very descriptive title to this issue.
- [X] I already read and followed all the tutorial in the docs and didn't find an answer.
- [X] I already checked if it is not related to AuthX but to Pydantic.
- [X] I already checked if it is not related to AuthX but to FastAPI.
Example Code
from authx import Authentication, MongoDBBackend
import motor.motor_asyncio
import asyncio
auth = Authentication(
backend=MongoDBBackend(
client=motor.motor_asyncio.AsyncIOMotorClient(
'mongodb://localhost:27017',
io_loop=asyncio.get_event_loop()
),
database='authx',
collection='users'
)
)
Description
This should ideally create an auth object that can be used to include routers. Instead this gives an error
backend=MongoDBBackend(
TypeError: __init__() got an unexpected keyword argument 'client'
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.77.1
Python Version
Python 3.9.0
Additional Context
This problem is arising as the MongoDBBackend class is not excepting any other parameters other than the database_name
class MongoDBBackend(BaseDBBackend):
"""
Setup Database for authx using MongoDB & Motor
"""
def __init__(self, database_name: str = "test") -> None:
self._database_name = database_name
def set_client(self, client: AsyncIOMotorClient) -> None:
self._client = client
self.init()
def init(self) -> None:
self._db: AsyncIOMotorDatabase = self._client[self._database_name]
self._users: AsyncIOMotorCollection = self._db["users"]
self._email_confirmations: AsyncIOMotorCollection = self._db[
"email_confirmations"
]
self._counters: AsyncIOMotorCollection = self._db["counters"]
self._settings: AsyncIOMotorCollection = self._db["settings"]