Where can I find a simple example of login using a local database? I need to prevent any page from being displayed, if the user is not logged in. The user can login against a database, or against a hashed key in a local file. I will only need a couple of users or three in my application.
My lack of knowledge about login management in web pages is causing me to have a finished application without managing user authentication, and not being able to deploy it because of that.
The documentation I can find is old, or perhaps a bit complex, or authenticates against other services.
I think my lack of knowledge about cookie management and user persistence led me to over-document.
Iâm going to take both examples, clone them, and start transferring the concepts I really need to perform a simple but secure validation of a couple of users, which is what I need for my project.
Thank you very much for the contribution! Itâs very concise and accurate!
If I want to use Reflex hosting, which currently doesnât support databases, I need to direct reflex-local-auth to an external database, like SQL Server. Is it possible to do this? I canât find how to do it.
Yes!
It is enough to add:
db_url=f"mssql+pymssql://{username}:{password}@{host}:{port}/{database}?charset=utf8",
to rxconfyg.py, as the example:
config = rx.Config(
app_name=âweb_appâ,
db_url=f"mssql+pymssql://{username}:{password}@{host}:{port}/{database}?charset=utf8",
)
But when I change from the local database SQLite to SQL Server, and I do:
reflex db makemigrations
I obtain this error:
alembic.util.exc.CommandError: Canât locate revision identified by â9f88a9f52875â
I answer myself. The reason was that the alembic table already existed in the target database in SQL Server, from previous tests. Simply drop it.
I hope this information will be useful to someone
The problem comes now with reflex-local-auth , which generates this error when deploying the database in SQL Server:
File âsrc_pymssql.pyxâ, line 465, in pymssql._pymssql.Cursor.execute
sqlalchemy.exc.OperationalError:
(pymssql.exceptions.OperationalError) (1919, b âColumn âsession_idâ in table âlocalauthsessionâ is of a type that is invalid for use as a key column in an index.DB-Lib error message 20018, severity 16:General SQL Server error: Check messages from the SQL Serverâ)
[SQL: CREATE UNIQUE INDEX ix_localauthsession_session_id ON localauthsession (session_id)]
It seems that reflex-local-auth is not compatible with SQL Server.