49 lines
963 B
PHP
49 lines
963 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class AuthService
|
|
{
|
|
/**
|
|
* 웹 세션 로그인
|
|
*/
|
|
public function login(array $credentials, bool $remember = false): bool
|
|
{
|
|
return Auth::attempt($credentials, $remember);
|
|
}
|
|
|
|
/**
|
|
* 로그아웃
|
|
*/
|
|
public function logout(): void
|
|
{
|
|
Auth::logout();
|
|
}
|
|
|
|
/**
|
|
* API 토큰 생성 (향후 사용)
|
|
*/
|
|
public function createToken(array $credentials): ?string
|
|
{
|
|
$user = User::where('email', $credentials['email'])->first();
|
|
|
|
if (! $user || ! Hash::check($credentials['password'], $user->password)) {
|
|
return null;
|
|
}
|
|
|
|
return $user->createToken('mng-token')->plainTextToken;
|
|
}
|
|
|
|
/**
|
|
* 현재 인증된 사용자 정보
|
|
*/
|
|
public function user(): ?User
|
|
{
|
|
return Auth::user();
|
|
}
|
|
}
|