popolo - code simple..

popolo - code simple..

Masonite Project - Adding Authentication Scaffold

Masonite Project - Adding Authentication Scaffold

Theodoros Kafantaris's photo
Theodoros Kafantaris
·Apr 15, 2022·

1 min read

Since that we have successfully installed Masonite, we are ready to proceed further with authentication scaffolding. Masonite is offering this functionality out of the box.

python craft auth

image.png

In order to take this effect we must add Auth.routes() in web.py:

from masonite.routes import Route
from masonite.authentication import Auth


ROUTES = [Route.get("/", "WelcomeController@show"),
          Auth.routes()
]

Now, we can visit http://127.0.0.1:8000/register

image.png

and http://127.0.0.1:8000/login

image.png

Let's prepare the DB in order to run the migrations. I use mysql DB so we need to install the following package for this connection.

pip install pymysql

image.png

Now let's create a new DB with name masonite. I am using Tableplus for Mac.

image.png

Now let's finish the configuration in .env for Masonite connection to Mysql.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=masonite
DB_USERNAME=root
DB_PASSWORD=password
DB_LOG=True

Now everything is ready to run migration and create user table in mysql.

python craft migrate

image.png

That's it! We are ready to register in our application!

 
Share this