About this guide
This development guide walks you through everything you need to do to build a high-quality Next.js app integrated with Supabase Auth and Bootstrap. Check out the tasks below to get started. To save time, you can also use our boilerplate, which gives you a complete React codebase with all of these tasks done for you. Okay, let's dive in!
Tasks
Setup your Next.js app
Create a Next.js app usingnpx create-next-appand then run your project locally with thenpm run devcommand.Create a Supabase AuthProvider and useAuth hook
Create anAuthProvidercomponent that fetches the current user from Supabase, subscribes to changes, stores the user in state, and then makes all this data available to child components usingContext.Provider. Make sure to update your Next.jsAppcomponent so thatAuthProviderwraps all your pages. You'll then create auseAuthhook that reads the user withuseContextand returns its value. This will enable any component to calluseAuthto get the current user and re-render when it changes.Protect pages with a Supabase requireAuth HOC
Create arequireAuthhigher order component for pages that should only be viewable by authenticated users. It should call youruseAuthhook internally to get the current user, show a loading indicator while waiting on the response, and then either render the page or redirect to/signindepending on whether the user is authenticated. For the loading indicator you might try aSpinnercomponent centered on the page.Build your authentication UI
Create an authentication UI using Bootstrap components and Supabase functions. You'll want routes for user sign-up, sign-in, forgot password, and change password. Make sure you properly validate inputs and display any errors returned by Supabase. You may also want to use a library, such as React Hook Form, for managing form state.Link user to analytics session
You can connect Google Analytics sessions to the current authenticated user with the User ID feature. This allows you to see what your users are doing across sessions and devices. You'll need to update youruseAuthhook to set theuser_idproperty whenever the user changes.Ensure Bootstrap link components hook into Next.js routing
Make all Bootstrap link components hook into Next.js routing by wrapping them with theLinkcomponent fromnext/linkand settingpassHrefto true.Create a persistent layout
Add any components that you'd like displayed across all pages (such asNavbarandFooter) to your Next.jsAppcomponent. If you need multiple persistent layouts you can instead have each page define its own layout. In that case, create multiple layout components (such asLandingPageLayoutandAdminLayout) and wrap the contents of each page.Finish your app UI with Bootstrap
Build out the rest of your UI using Bootstrap components and composing them into high-level page sections, such asHeroSectionandAccountSettings. Use SASS stylesheets for styling your components and overriding default component styles. You can scope each stylesheet to a single component using BEM syntax or CSS Modules.You should find our library of pre-built Bootstrap components to be helpful.
Get the code
You can get the code for this guide with our Next.js, Supabase Auth, and Bootstrap Boilerplate. You'll get a complete Next.js codebase with Supabase Auth and Bootstrap integration, all the tasks listed above done for you, and a responsive multi-page template. It should save you about two weeks of development time.
127 downloads today