Adding Registration and Login

To add Registration and Login web pages is as simple as setting up a route in our Routes.swift and creating a Leaf template file that will render the HTML forms. For our Leaf template, we will need to create a signup form for the new user and a login form for users that have registered already. To get started with adding these forms to our Vapor app, we need to follow these steps:

  1. First, open the Routes.swift file and remove everything inside the setupRoutes method as we will be setting up two kinds of routes, one for authenticated users and another for unauthenticated.
  2. Next, import the AuthProvider and Sessions dependencies that we will need later by adding the following two lines to the top of the file:

Get Hands-On Full-Stack Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.