API — Ship Fast ⚡️

API calls

Our front-end uses the apiClient (see /libs/api.js) to communicate with our back-end (NextJS /api)

The front-end client handles errors gracefully: show error toasts, redirects on login if err 401, etc..

The back-end should send back a JSON response with a message key if an error occurs, like this:

return res.status(500).json({
  error: "Something went wrong",
});

Authentification

We use Next-Auth to login users and make authentificated calls to our back-end.

Here are the tutorials to set up Google Login and Email Login. You can use next-auth to add any other Oauth provider.

Private routes (i.e. user account)

If you add the hook usePrivate() to any page, it will redirect to the login page if the user is not logged in.

Check the code examples to do it on the front-end (private page) & back-end (private route)