An implementing of the Laravel Breeze application / authentication starter kit frontend in Next.js

Overview

Windmill with Laravel Breeze as Backend API

Introduction

This repository is an implementing of the Laravel Breeze application / authentication starter kit frontend in Next.js. All of the authentication boilerplate is already written for you - powered by Laravel Sanctum, allowing you to quickly begin pairing your beautiful Next.js frontend with a powerful Laravel backend.

Official Documentation

Installation

First, create a Next.js compatible Laravel backend by installing Laravel Breeze into a fresh Laravel application and installing Breeze's API scaffolding:

# Create the Laravel application...
laravel new next-backend

cd next-backend

# Install Breeze and dependencies...
composer require laravel/breeze

php artisan breeze:install api

Next,

  • Ensure that your application's APP_URL and FRONTEND_URL environment variables are set to http://localhost:8000 and http://localhost:3000/example, respectively.

  • In app/Providers/RouteServiceProvider.php, update : public const HOME = '/';

  • In app/Http/Middleware/Authenticate.php, update :

protected function redirectTo($request)
{
    if (! $request->expectsJson()) {
        return config('app.frontend_url').'/login?next_to='.urlencode($request->url());
    }
}
  • In app/Http/Middleware/RedirectIfAuthenticated.php, update :
public function handle(Request $request, Closure $next, ...$guards)
{
    $guards = empty($guards) ? [null] : $guards;

    foreach ($guards as $guard) {
        if (Auth::guard($guard)->check()) {
            return redirect(config('app.frontend_url').RouteServiceProvider::HOME);
        }
    }

    return $next($request);
}
  • In config/cors.php, update :
['*'], 'allowed_methods' => ['*'], 'allowed_origins' => [$frontedUrl], 'allowed_origins_patterns' => [], 'allowed_headers' => ['*'], 'exposed_headers' => [], 'max_age' => 0, 'supports_credentials' => true, ]; ">


$frontedUrl = env('FRONTEND_URL', '*');

if ($frontedUrl !== '*') {
    $parsed = parse_url($frontedUrl);
    $frontedUrl = sprintf(
        '%s://%s%s',
        $parsed['scheme'],
        $parsed['host'],
        isset($parsed['port']) ? ':' . $parsed['port'] : ''
    );
}

return [

    /*
    |--------------------------------------------------------------------------
    | Cross-Origin Resource Sharing (CORS) Configuration
    |--------------------------------------------------------------------------
    |
    | Here you may configure your settings for cross-origin resource sharing
    | or "CORS". This determines what cross-origin operations may execute
    | in web browsers. You are free to adjust these settings as needed.
    |
    | To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
    |
    */

    'paths' => ['*'],

    'allowed_methods' => ['*'],

    'allowed_origins' => [$frontedUrl],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => [],

    'max_age' => 0,

    'supports_credentials' => true,

];

After defining the appropriate environment variables and update several codes above, you may serve the Laravel application using the serve Artisan command:

# Serve the application...
php artisan serve

Next, clone this repository and install its dependencies with yarn install or npm install. Then, copy the .env.example file to .env.local and supply the URL of your backend:

NEXT_PUBLIC_BACKEND_URL=http://localhost:8000

Finally, run the application via yarn dev or npm run dev. The application will be available at http://localhost:3000:

yarn dev

# or

npm run dev

Note: Currently, we recommend using localhost during local development of your backend and frontend to avoid CORS "Same-Origin" issues.

Authentication Hook

This Next.js application contains a custom useAuth React hook, designed to abstract all authentication logic away from your pages. In addition, the hook can be used to access the currently authenticated user:

const ExamplePage = () => {
    const { logout, user } = useAuth({ middleware: 'auth' })

    return (
        <>
            <p>{user?.name}</p>

            <button onClick={logout}>Sign out</button>
        </>
    )
}

export default ExamplePage

Note: You will need to use optional chaining (user?.name instead of user.name) when accessing properties on the user object to account for Next.js's initial server-side render.

About Windmill

Windmill Dashboard Next.js Typescript

Windmill Dashboard React

See the Original Project by @estevanmaito

This is not a template. This is a complete application, built on top of React, with all tiny details taken care of so you just need to bring the data to feed it.

Accessibility is a priority in my projects and I think it should be in yours too, so this was developed listening to real screen readers, focus traps and keyboard navigation are available everywhere.

📦 Features

  • 🦮 Throughly accessible (developed using screen readers)
  • 🌗 Dark theme enabled (load even different images based on theme)
  • 🧩 Multiple (custom) components
  • Code splitting
  • Tailwind CSS
  • Windmill React UI Documentation
  • Heroicons
  • Chart.js

📚 Docs

General components

Windmill Dashboard React is built on top of Windmill React UI.

See Windmill React UI Documentation

Example Boilerplate

All components and containers are saved in folder example

Routing

Change default redirecting when hit the / or home in file next.config.js

  async redirects() {
    return [
      {
        source: '/',
        destination: '/example/login',
        permanent: false,
      },
    ]
  }

Sidebar routes

To configure sidebar menus, see file (routes/sidebar.tsx).

These are the routes that will show in the sidebar. They expect three properties:

  • path: the destination;
  • name: the name to be shown;
  • icon: an icon to illustrate the item

Item that are used as dropdowns, like the Pages option, don't need a path, but expect a routes array of objects with path and name:

// sidebar.js
{
  path: '/example/tables',
  icon: 'TablesIcon',
  name: 'Tables',
},
{
  icon: 'PagesIcon', // <-- this is used as a submenu, so no path
  name: 'Pages',
  routes: [
    // submenu
    {
      path: '/example/login',
      name: 'Login', // <-- these don't have icons
    },
    {
      path: '/example/create-account',
      name: 'Create account',
    },

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, install dependencies :

npm install
# or
yarn install

then, you can run the development server:

npm run dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying pages/index.tsx. The page auto-updates as you edit the file.

API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.ts.

The pages/api directory is mapped to /api/*. Files in this directory are treated as API routes instead of React pages.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

You might also like...
A Laravel-Vue-Tailwind SAAS Starter Kit.

Super SAAS Template My name is Julien Nahum, I've founded multiple Software-As-A-Service companies. This repo is the base I'm using to create a new SA

A Laravel-Vue SPA starter kit.
A Laravel-Vue SPA starter kit.

Laravel-Vue SPA A Laravel-Vue SPA starter kit. Features Laravel 8 Vue + VueRouter + Vuex + VueI18n + ESlint Pages with dynamic import and custom layou

A starter kit that integrates Laravel with Vue CLI, Inertia.js, TailwindCSS and Vuetify
A starter kit that integrates Laravel with Vue CLI, Inertia.js, TailwindCSS and Vuetify

Laravel Viltify Laravel Viltify is a heavily opinionated Laravel starter kit. It's intent is to seamlessly integrate V ue, I nertia.js, L aravel, T ai

An administration starter kit for Laravel.
An administration starter kit for Laravel.

Craftable About Demo Packages used Requirements Installation New project Add to existing project Basics Documentation Where to go next? About Hi Craft

It's a dashboard theme/UI-Starter Kit with Laravel, Inertia and Vue (JetStream).

TailAdmin Inertia It's a dashboard theme/UI-Starter Kit with Laravel, Inertia and Vue (JetStream). Setup Directions npm install composer install Chang

Laravel Boilerplate / Starter Kit with Gentelella Admin Theme
Laravel Boilerplate / Starter Kit with Gentelella Admin Theme

Laravel Boilerplate Project Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications. Table of Con

Laravel Starter Kit (Inertia-SSR - Vue3 - Bootstrap 5)
Laravel Starter Kit (Inertia-SSR - Vue3 - Bootstrap 5)

Laravel Starter Kit (Inertia-SSR - Vue3 - Bootstrap 5) Use this starter kit to develop with Laravel 9 setup InertiaJs with Server Side Rendering (SSR)

Surf, an opinionated fork of Wave - the SAAS starter kit, with Laravel 9.
Surf, an opinionated fork of Wave - the SAAS starter kit, with Laravel 9.

Surf 🏄‍♀️ Introduction Surf, the opinionated Software as a Service Starter Kit that can help you build your next great idea 💰 . Surf is fork off Wav

An Starter Kit For Laravel Projects.
An Starter Kit For Laravel Projects.

Laravel Starter Kit An Starter Kit For Laravel Projects. Installation 1-Install the package via composer: composer require xmen/starter-kit --with-al

Comments
  • [Question] Explanation of setStatus

    [Question] Explanation of setStatus

    Hello Sorry to bother you, Could you please explain a little bit about setStatus and it's usage? It's almost setStatus(null) most of places and only in login:

      useEffect(() => {
        const reset = query && query.reset ? query.reset as string : ''
        if (reset.length > 0 && errors.length === 0) {
          setStatus(atob(reset))
        } else {
          setStatus(null)
        }
      }, [query, errors])
    
    

    Many Thanks in advance

    opened by sinar93 0
Owner
ROKET ID
ROKET ID
This is a laravel Auth Starter Kit, with full user/admin authentication with both session and token auth

About Auth Starter It's a Laravel 8 authentication markdown that will help you to understand and grasp all the underlying functionality for Session an

Sami Alateya 10 Aug 3, 2022
👔 Enterprise Web application starter kit or template using Laravel

Laravel Enterprise Starter Kit (LESK) Description LESK, is a template project based on the Laravel LTS, combining a set of features that can kick star

Sebastien Routier 1 Dec 31, 2020
A Laravel Starter Kit for Laravel. Built with Laravel 8.

Laravel Get Started Project Laravel Get Started Project is a basic crud app built with laravel 8. In this app a basic product crud created. Features i

Nazmul Hasan Robin 8 Nov 24, 2022
React laravel starter kit with tailwind css and vite js(laravel 9)

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Jerald Tonmoy Dias 2 Dec 23, 2022
Laravel API starter Kit will provide you with the tools for making API's that everyone will love

Laravel API Starter Kit Laravel API starter Kit will provide you with the tools for making API's that everyone will love, API Authentication is alread

Jose Luis Fonseca 400 Dec 29, 2022
Laravel + Livewire + Bootstrap 5 UI starter kit.

bastinald/ui Laravel + Livewire + Bootstrap 5 UI starter kit. Requirements Laravel 8 NPM Features Bootstrap 5 pre-configured Textarea autosize Floatin

null 83 Dec 26, 2022
a free, open-source dashboard panel starter kit for Laravel

QAdmin a free, open-source dashboard panel starter kit for Laravel. Just intall and everything is ready Tech Stack Client: ruangAdmin, Bootstrap, Jque

null 30 Oct 11, 2022
A simple starter kit for using TypedCMS with the Laravel framework.

TypedCMS Starter Kit for Laravel Our stater kits are tailored solutions for each platform, unlike the simple API wrappers offered by other vendors. Th

TypedCMS 1 Nov 20, 2021
Laravel React Webpack Starter Kit

About Laravel Laravel React Webpack Starter Kit This starter kit is designed to get you up and running with with react.js with Laravel, built on top o

Biju Nakarmi 32 Nov 24, 2022
A Laravel-Nuxt starter kit.

Laravel-Nuxt A Laravel-Nuxt starter project template. Features Nuxt 2 Laravel 8 SPA or SSR Socialite integration VueI18n + ESlint + Bootstrap 4 + Font

Cretu Eusebiu 1.1k Jan 5, 2023