"passport install" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "passport install" answered properly. Developers are finding an appropriate answer about passport install related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like passport install. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on passport install.
install passport local
$ npm install passport-local
Source: www.passportjs.org
laravel token authentication
# Database Preparation
// add api_token to users table
Schema::table('users', function ($table) {
$table->string('api_token', 80)->after('password')
->unique()
->nullable()
->default(null);
});
// Create token for existing users, code can also be added to registerController
$token = Str::random(60);
$user = User::find(1);
$user->api_token = hash('sha256', $token); // <- This will be used in client access
$user->save();
//config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token', // <- Add this entry
'provider' => 'users',
'hash' => false,
],
],
//routes/api.php
// Add "middleware('auth:api')" as below
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
//client access example (in Vue js)
axios.get('http://example.com/api/user',
{
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer '+ 'user-api-token'
}
}
)
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
Source: laravel.com
All those coders who are working on the Whatever based application and are stuck on passport install can get a collection of related answers to their query. Programmers need to enter their query on passport install related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about passport install for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of passport install while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "passport install". Visit this developer's friendly online web community, CodeProZone, and get your queries like passport install resolved professionally and stay updated to the latest Whatever updates.