Last active
October 30, 2018 21:34
-
-
Save spacemudd/22f1cfd9e1c562de1c1af9950e1e8f9e to your computer and use it in GitHub Desktop.
Laravel Passport + Nuxt Auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::post('auth/login', function(Request $request) { | |
$cred = $request->only('email', 'password'); | |
if (auth()->attempt($cred)) { | |
auth()->user()->tokens()->delete(); | |
$token = auth()->user()->createToken('SPA'); | |
return response()->json([ | |
'access_token' => $token->accessToken, | |
]); | |
} | |
return response()->json(['Unauthorized.'], \Illuminate\Http\Response::HTTP_UNAUTHORIZED); | |
}); | |
Route::group(['middleware' => 'auth:api'], function() { | |
Route::get('auth/user', function(Request $request) { | |
return auth()->user(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
auth: { | |
login: '/login', | |
logout: '/', | |
strategies: { | |
local: { | |
endpoints: { | |
login: {url: '/api/auth/login', method: 'post', propertyName: 'access_token'}, | |
logout: {url: '/api/auth/logout', method: 'post', }, | |
user: {url: '/api/auth/user', method: 'get', propertyName: 'user'}, | |
}, | |
tokenRequired: true, | |
tokenType: 'Bearer', # Case sensitive when dealing with Laravel backend. | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment