Laravel은 강력한 스캐폴딩으로 인증을 위한 여러 옵션을 편리하게 제공한다.
Laravel Starter Kit에는 Laravel Breeze와 Laravel Jetstream이 포함되어 있습니다.
- Laravel Breeze는 인증 작업을 빠르게 실행하는데 적합
- Jetstream은 2단계 인증, API 토큰 및 팀 관리를 제공합니다.
둘다 로그인을 제공한다.
인증과 관련된 더 많은 기능을 찾고 있다면 Jetstream이 적합합니다.
신속하게 로그인 기능을 구현해야 할때
Laravel Breeze
회원등록, 로그인, 로그아웃, 간단한 로그인과 관련된 기능을 제공합니다.
Breeze 설치
composer create-project laravel/laravel project-name
cd project-name
composer require laravel/breeze --dev
php artisan breeze:install
npm install
npm run dev
Breeze 폴더 및 파일 구조
# routes/web.php
require__DIR__.'/auth.php';
Controllers
app/Http/Controllers/Auth/
- AuthenticatedSessionController.php
- ConfirmablePasswordController.php
- EmailVerificationNotificationController.php
- EmailVerificationPromptController.php
- NewPasswordController.php
- PasswordController.php
- PasswordResetLinkController.php
- RegisteredUserController.php
- VerifyEmailController.php
Views
resource/views/auth/
- confirm-password.blade.php
- forgot-password.blade.php
- login.blade.php
- register.blade.php
- reset-password.blade.php
- verify-email.blade.php
API 인증, 세션관리, 팀관리, 2단계 인증, 메일인증
Laravel Jetstream
설치하기
global laravel installer 이용해서 설치
2023.11.19 - [Laravel] - Laravel - global 로 laravel 프로젝트 생성 명령어 설정하기
laravel new project-name --jet
cd project-name
php artisan migrate
php artisan serve
또는 composer 를 이용한 설치
composer create-project laravel/laravel project-name
cd project-name
composer require laravel/jetstream
php artisan jetstream:install livewire --teams
# 또는
php artisan jetstream:install inertia --teams
npm install && npm run dev
php artisan migrate
인증관련
resources/views/auth
app/actions/Fortify
config/fortify.php
프로파일
resources/views/profile/update-profile-information-form.blade.php
보안
Two-factor Authentication (2FA) with QR code.
http://resources/views/profile/
API
Laravel Sanctum
Teams
팀구성 및 관리 제공
Breeze 설치 후 Jetstream 을 설치하면 기존에 생성된 파일이 변경되고 에러가 발생한다.
방법은 db table을 모두 삭제하고 다시 migrate 한다.
가능하면 처음부터 Jetstream 를 설치하도록 한다.
Breeze 를 설치하고 나중에 Jetstream 을 설치하는 경우..
1. routes/web.php 주석처리함.
//require __DIR__.'/auth.php';
2. config/fority.php
'features' => [
Features::registration(),
Features::resetPasswords(),
Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
// 'window' => 0,
]),
],
3. config/jetstream.php
'features' => [
// Features::termsAndPrivacyPolicy(),
Features::profilePhotos(),
Features::api(),
Features::teams(['invitations' => true]),
Features::accountDeletion(),
],
4. 다음 파일이 생성되어 있어야 한다.
만약 Breeze 에서 등록한 회원이 있다면 모두 삭제하고 다시 등록해야 한다.
--teams 옵션으로 jetsteam 을 설정하면 회원 로그인 시 에러가 발생하기 때문이다.
메일확인 후 계정이 등록되게 하려면
app/Models/User.php
class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens;
use HasFactory;
use HasProfilePhoto;
use HasTeams;
use Notifiable;
use TwoFactorAuthenticatable;
인터페이스 MustVerifyEmail 을 추가해 준다.
.env 환경설정 파일에서 메일 서버를 등록해주고 회원가입을 진행해야 한다. 그렇지 않으면 에러가 발생한다.
'Laravel' 카테고리의 다른 글
Laravel - CRUD 기본 코드 (0) | 2023.12.01 |
---|---|
Laravel - Request 객체 다루기 (0) | 2023.11.21 |
Laravel - Jetstream Teams 설치하기 (0) | 2023.11.19 |
Laravel - global 로 laravel 프로젝트 생성 명령어 설정하기 (0) | 2023.11.19 |
Laravel - 테스트용 데이타 자동으로 입력하기 (db:Seed, Factory) (0) | 2023.11.14 |