-
Notifications
You must be signed in to change notification settings - Fork 2
Authentication
Authentication in our application is handled by NextAuth, an authentication library supporting major OAuth providers and built for ease of use with NextJS.
To start, we've already included ready to go signup and login mechanisms, along with their complementary backend logic bundled with NextAuth. You can view the code for the login and signup views at pages/auth/login
and pages/auth/signup
. They make use of the FullPageForm
component to make simple pages that fill up the whole viewport with a form in the middle. The callbackUrl
represents the route that the form will post to when submitted. Any errors in the form will be returned in the form of a query string and will be displayed to the user in red text.
Login will ultimately resolve with the authenticate
function in api\users\login
. NextAuth will automatically take care of cookies and maintaining a session. More documentation will be available soon on persisting user data in cookies.
Signup will resolve with the signup function within UserController
in server\controllers\UserController.tsx
Currently it simply takes a username and password as the only information for the User document, but you can pass in as many fields as you want in the body of the request, as long as its validated first. As the FullPageForms don't resolve asynchronously, we redirect the client to the relevant page (login upon success, back to the signup page if error along with error query string if error) when the function resolves using this.res.redirect($url)
.