• Blog
  • Documentation
  • Courses
  • Changelog
  • AI Starters
  • UI Kit
  • FAQ
  • Supamode
    New
  • Pricing

Launch your next SaaS in record time with Makerkit, a React SaaS Boilerplate for Next.js and Supabase.

Makerkit is a product of Makerkit Pte Ltd (registered in the Republic of Singapore)Company Registration No: 202407149CFor support or inquiries, please contact us

About
  • FAQ
  • Contact
  • Verify your Discord
  • Consultation
  • Open Source
  • Become an Affiliate
Product
  • Documentation
  • Blog
  • Changelog
  • UI Blocks
  • Figma UI Kit
  • AI SaaS Starters
License
  • Activate License
  • Upgrade License
  • Invite Member
Legal
  • Terms of License
  • Global Configuration
    • Environment Variables
    • Feature Flags
  • Server Actions
    • Sending CSRF Token to Actions
    • Server Actions Error Handling
  • The Makerkit SDK
    • User SDK
    • Organization SDK
    • Organization Subscription SDK
    • Data Loader SDK
  • Architecture and Folder Structure
    • Structure your Application
    • Data Model
    • Introduction
    • Initial Setup
    • Running the App
    • Project Configuration
    • Environment Variables
    • Tailwind CSS and Styling
    • Authentication
    • Onboarding Flow
    • Database Schema
    • Supabase: Data Fetching
    • Supabase: Data Writing
    • Routing
    • Building the Tasks page
    • Building the Task Detail page
    • API Routes
    • Application Pages
    • API Routes Validation
    • Translations
    • Functions you need to know
    • Adding pages to the Marketing Site
    • Deploying to Production
    • Updating to the latest version
This documentation is for a legacy version of Next.js and Supabase. For the latest version, please visit the Next.js and Supabase V2 documentation

Application Pages

Learn how to create and manage application pages in your Makerkit app

Now that we have some components to display, we need to add them to the actual Next.js pages.

If you have not created the files in the Routing section above, it's time to do it.

Using the components AppHeader and AppContainer

These components are used to wrap the content of the pages.

They are responsible for displaying the header and the container of the page.

tsx
import { Squares2X2Icon } from '@heroicons/react/24/outline';
import Trans from '~/core/ui/Trans';
import AppHeader from '~/app/dashboard/[organization]/components/AppHeader';
import AppContainer from '~/app/dashboard/[organization]/components/AppContainer';
function DashboardPage() {
return (
<>
<AppHeader>
<span className={'flex space-x-2'}>
<Squares2X2Icon className="w-6" />
<span>
<Trans i18nKey={'common:dashboardTabLabel'} />
</span>
</span>
</AppHeader>
<AppContainer>
Your content goes here
</AppContainer>
</>
);
}

Guarding Application Pages for Authenticated Users

One of the ways we can use to protect application pages, we can use the requireSession function. This function also verifies that the user is authenticated using MFA.

tsx
import { redirect } from "next/navigation";
async function MyPage() {
const session = await requireSession();
if (!session) {
redirect('/');
}
}

If you don't want to redirect users away, you can simply display an error message instead.

tsx
import { redirect } from "next/navigation";
async function MyPage() {
const session = await requireSession();
if (!session) {
return <div>You are not authenticated</div>;
}
return <div>Your content goes here</div>;
}

Using Dynamic Parameters

Every page and layout can access dynamic parameters from the URL.

For example, if you have a page with the following URL:

text
https://myapp.com/dashboard/[organization]/[project]

You can access the organization and project parameters from the page.

tsx
interface PageData {
params: {
organization: string;
project: string;
}
}
function Page(data: PageData) {
// data.params.organization
}

Using Search Parameters

Similarly to dynamic parameters, you can also access search parameters from the URL.

For example, if you have a page with the following URL:

text
https://myapp.com/dashboard/[organization]/[project]?page=1&limit=10

You can access the page and limit parameters from the page.

tsx
interface PageData {
params: {
organization: string;
project: string;
}
searchParams: {
page: string;
limit: string;
}
}
function Page(data: PageData) {
// data.searchParams.page
}

Internationalization

To enable i18n for a layout or a route, simply wrap them using the withI18n HOC.

This component makes sure that the i18n is initialized before the page is rendered.

tsx
import { withI18n } from '~/i18n/with-i18n';
function TaskPage() {
// ...
}
export default withI18n(TaskPage);
On this page
  1. Guarding Application Pages for Authenticated Users
    1. Using Dynamic Parameters
      1. Using Search Parameters
        1. Internationalization