Docker × Laravel 8 Jetstream으로 로그인, 사용자 등록, 2단계 인증 구현

Laravel Jetstream은 Laravel8에서 사용할 수 있는 새로운 패키지로, Laravel7 이전에 이용되고 있던 Laravel UI의 후속 패키지입니다.
  • Jetstream 공식 문서

  • Laravel Jetstream 기능


  • 로그인 기능
  • 사용자 등록 기능
  • 메일 확인
  • 2 요소 인증
  • 세션 관리

  • Laravel Sanctum을 통한 API 지원
  • 팀 관리


  • 위의 기능을 제공합니다.

    Laravel Jetstream의 특징



    Jetstream은 Tailwind CSS를 사용하여 설계되었습니다.
    템플릿으로 Livewire 또는 Inertia을 선택할 수 있습니다.
  • Livewire는 주로 Blade로 쓰는 사람을위한 (SEO, OGP 필요)
  • Inertia는 주로 Vue로 쓰는 사람 (SPA)

  • 환경


  • PHP: 7.4.4
  • Laravel: 8.1.0
  • Node: 14.2.0
  • Yarn: 1.22.4
  • Laravel Jetstream: 0.6.0

  • 환경으로서 이쪽의 기사, 리포지토리를 참고로 합니다.
  • 최강의 Laravel 개발 환경을 Docker를 사용해 구축하는 【신편집판】
  • htps : // 기주 b. 코 m / 우칸 - b / 도 c 케 r - 라라 ょ l
  • $ git clone [email protected]:ucan-lab/docker-laravel.git
    $ cd docker-laravel
    $ make create-project
    

    비밀번호 재설정 메일의 동작 확인을 하고 싶은 경우는 아래의 기사에서 메일 컨테이너를 추가하면 확인할 수 있습니다.
  • Docker × Laravel 메일 전송 프로세스를 로컬에서 확인

  • Livewire(Blade) 설치


    $ make app
    $ composer require laravel/jetstream
    $ php artisan jetstream:install livewire
    $ php artisan migrate
    $ exit
    
    $ make web
    $ yarn install
    $ yarn dev
    $ exit
    



    Welcome 화면이 표시되면 ok

    보충: Livewire 파일 차이


    $ git status -s
     M .env.example
     M app/Http/Kernel.php
     M app/Models/User.php
     M app/Providers/RouteServiceProvider.php
     M composer.json
     M composer.lock
     M config/app.php
     M config/session.php
     M database/migrations/2014_10_12_000000_create_users_table.php
     M package.json
     M resources/css/app.css
     M resources/views/welcome.blade.php
     M routes/api.php
     M routes/web.php
     M webpack.mix.js
    ?? app/Actions/Fortify/CreateNewUser.php
    ?? app/Actions/Fortify/PasswordValidationRules.php
    ?? app/Actions/Fortify/ResetUserPassword.php
    ?? app/Actions/Fortify/UpdateUserPassword.php
    ?? app/Actions/Fortify/UpdateUserProfileInformation.php
    ?? app/Actions/Jetstream/DeleteUser.php
    ?? app/Providers/FortifyServiceProvider.php
    ?? app/Providers/JetstreamServiceProvider.php
    ?? app/View/Components/AppLayout.php
    ?? app/View/Components/GuestLayout.php
    ?? config/fortify.php
    ?? config/jetstream.php
    ?? config/sanctum.php
    ?? database/migrations/2014_10_12_200000_add_two_factor_columns_to_users_table.php
    ?? database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php
    ?? database/migrations/2020_09_11_191956_create_sessions_table.php
    ?? public/css/app.css
    ?? resources/views/api/api-token-manager.blade.php
    ?? resources/views/api/index.blade.php
    ?? resources/views/auth/forgot-password.blade.php
    ?? resources/views/auth/login.blade.php
    ?? resources/views/auth/register.blade.php
    ?? resources/views/auth/reset-password.blade.php
    ?? resources/views/auth/two-factor-challenge.blade.php
    ?? resources/views/auth/verify-email.blade.php
    ?? resources/views/dashboard.blade.php
    ?? resources/views/layouts/app.blade.php
    ?? resources/views/layouts/guest.blade.php
    ?? resources/views/profile/delete-user-form.blade.php
    ?? resources/views/profile/logout-other-browser-sessions-form.blade.php
    ?? resources/views/profile/show.blade.php
    ?? resources/views/profile/two-factor-authentication-form.blade.php
    ?? resources/views/profile/update-password-form.blade.php
    ?? resources/views/profile/update-profile-information-form.blade.php
    ?? tailwind.config.js
    

    Inertia(Vue) 설치


    $ make app
    $ composer require laravel/jetstream
    $ php artisan jetstream:install inertia --teams
    $ php artisan migrate
    $ exit
    
    $ make web
    $ yarn install
    $ yarn dev
    $ exit
    



    Welcome 화면이 표시되면 ok

    보충: Inertia 파일 차이


    $ git status -s
     M backend/.env.example
     M backend/app/Http/Kernel.php
     M backend/app/Models/User.php
     M backend/app/Providers/AuthServiceProvider.php
     M backend/app/Providers/RouteServiceProvider.php
     M backend/composer.json
     M backend/composer.lock
     M backend/config/app.php
     M backend/config/session.php
     M backend/database/migrations/2014_10_12_000000_create_users_table.php
     M backend/package.json
     M backend/resources/css/app.css
     M backend/resources/js/app.js
     M backend/resources/views/welcome.blade.php
     M backend/routes/api.php
     M backend/routes/web.php
     M backend/webpack.mix.js
    ?? backend/app/Actions/Fortify/CreateNewUser.php
    ?? backend/app/Actions/Fortify/PasswordValidationRules.php
    ?? backend/app/Actions/Fortify/ResetUserPassword.php
    ?? backend/app/Actions/Fortify/UpdateUserPassword.php
    ?? backend/app/Actions/Fortify/UpdateUserProfileInformation.php
    ?? backend/app/Actions/Jetstream/AddTeamMember.php
    ?? backend/app/Actions/Jetstream/CreateTeam.php
    ?? backend/app/Actions/Jetstream/DeleteTeam.php
    ?? backend/app/Actions/Jetstream/DeleteUser.php
    ?? backend/app/Actions/Jetstream/UpdateTeamName.php
    ?? backend/app/Models/Membership.php
    ?? backend/app/Models/Team.php
    ?? backend/app/Policies/TeamPolicy.php
    ?? backend/app/Providers/FortifyServiceProvider.php
    ?? backend/app/Providers/JetstreamServiceProvider.php
    ?? backend/app/View/Components/GuestLayout.php
    ?? backend/config/fortify.php
    ?? backend/config/jetstream.php
    ?? backend/config/sanctum.php
    ?? backend/database/migrations/2014_10_12_200000_add_two_factor_columns_to_users_table.php
    ?? backend/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php
    ?? backend/database/migrations/2020_05_21_100000_create_teams_table.php
    ?? backend/database/migrations/2020_05_21_200000_create_team_user_table.php
    ?? backend/database/migrations/2020_09_11_221935_create_sessions_table.php
    ?? backend/public/css/app.css
    ?? backend/resources/js/Jetstream/ActionMessage.vue
    ?? backend/resources/js/Jetstream/ActionSection.vue
    ?? backend/resources/js/Jetstream/ApplicationLogo.vue
    ?? backend/resources/js/Jetstream/ApplicationMark.vue
    ?? backend/resources/js/Jetstream/Button.vue
    ?? backend/resources/js/Jetstream/ConfirmationModal.vue
    ?? backend/resources/js/Jetstream/DangerButton.vue
    ?? backend/resources/js/Jetstream/DialogModal.vue
    ?? backend/resources/js/Jetstream/Dropdown.vue
    ?? backend/resources/js/Jetstream/DropdownLink.vue
    ?? backend/resources/js/Jetstream/FormSection.vue
    ?? backend/resources/js/Jetstream/Input.vue
    ?? backend/resources/js/Jetstream/InputError.vue
    ?? backend/resources/js/Jetstream/Label.vue
    ?? backend/resources/js/Jetstream/Modal.vue
    ?? backend/resources/js/Jetstream/NavLink.vue
    ?? backend/resources/js/Jetstream/ResponsiveNavLink.vue
    ?? backend/resources/js/Jetstream/SecondaryButton.vue
    ?? backend/resources/js/Jetstream/SectionBorder.vue
    ?? backend/resources/js/Jetstream/SectionTitle.vue
    ?? backend/resources/js/Jetstream/SwitchableTeam.vue
    ?? backend/resources/js/Jetstream/Welcome.vue
    ?? backend/resources/js/Layouts/AppLayout.vue
    ?? backend/resources/js/Mixins/InteractsWithErrorBags.js
    ?? backend/resources/js/Pages/API/ApiTokenManager.vue
    ?? backend/resources/js/Pages/API/Index.vue
    ?? backend/resources/js/Pages/Dashboard.vue
    ?? backend/resources/js/Pages/Profile/DeleteUserForm.vue
    ?? backend/resources/js/Pages/Profile/LogoutOtherBrowserSessionsForm.vue
    ?? backend/resources/js/Pages/Profile/Show.vue
    ?? backend/resources/js/Pages/Profile/TwoFactorAuthenticationForm.vue
    ?? backend/resources/js/Pages/Profile/UpdatePasswordForm.vue
    ?? backend/resources/js/Pages/Profile/UpdateProfileInformationForm.vue
    ?? backend/resources/js/Pages/Teams/Create.vue
    ?? backend/resources/js/Pages/Teams/CreateTeamForm.vue
    ?? backend/resources/js/Pages/Teams/DeleteTeamForm.vue
    ?? backend/resources/js/Pages/Teams/Show.vue
    ?? backend/resources/js/Pages/Teams/TeamMemberManager.vue
    ?? backend/resources/js/Pages/Teams/UpdateTeamNameForm.vue
    ?? backend/resources/views/app.blade.php
    ?? backend/resources/views/auth/forgot-password.blade.php
    ?? backend/resources/views/auth/login.blade.php
    ?? backend/resources/views/auth/register.blade.php
    ?? backend/resources/views/auth/reset-password.blade.php
    ?? backend/resources/views/auth/two-factor-challenge.blade.php
    ?? backend/resources/views/auth/verify-email.blade.php
    ?? backend/resources/views/layouts/guest.blade.php
    ?? backend/tailwind.config.js
    

    Screen Shot (Livewire, Inertia 공통)



    welcome



    Jetstream을 설치하면 오른쪽 상단에 Login, Register 메뉴가 추가되었습니다.



    register



    사용자 등록 화면입니다.



    대시보드



    사용자가 등록하면 로그인되어 대시보드로 전환됩니다.



    프로필





    api tokens





    login





    password reset









    Screen Shot(Inertia)



    대시보드





    team settings





    create new team





    2요소 인증



    프로필 페이지에서 Two Factor Authentication을 활성화하면 QR 코드가 표시됩니다.
    Google Authenticator를 설치하고 카메라에서 QR 코드를 로드하면 이중 인증이 가능합니다.



    login 페이지를 진행하면 인증 코드를 요구하는 페이지가 표시된다.



    노코드로 여기까지 할 수 있다는 것은 두려워합니다 ...

    좋은 웹페이지 즐겨찾기