Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cesargb patch 1 #10

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added ability to specify other auth guard
  • Loading branch information
thesubhendu committed Jan 8, 2020
commit c99e7b46c80e91d99e6dd7b733f2483b1fdaa4ba
8 changes: 5 additions & 3 deletions src/MagicLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function add($user, $redirect_url = '', $lifetime = 0)
if (is_int($user)) {
$MagicLink->user_id = $user;
} else {
$MagicLink->user_id = $user->id;
$MagicLink->user_id = $user->getKey();
}

$MagicLink->token = Str::random(config('magiclink.token.length', 64));
Expand Down Expand Up @@ -51,10 +51,12 @@ public function auth($token)
->first();

if ($magicLink) {
$user = config('auth.providers.users.model')::find($magicLink->user_id);
$authProviderModel = config('magicklink.auth_provider').".model";

$user = config($authProviderModel)::find($magicLink->user_id);

if ($user) {
app()->make('auth')->loginUsingId($magicLink->user_id);
app()->make('auth')->guard(config('magicklink.auth_guard'), 'web')->loginUsingId($magicLink->user_id);

if ($magicLink->redirect_url !== null && $magicLink->redirect_url != '') {
return $magicLink->redirect_url;
Expand Down
2 changes: 1 addition & 1 deletion src/Models/MagicLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class MagicLink extends Model
{
public function user()
{
return $this->hasOne(config('auth.providers.users.model'), config('magiclink.user_primarykey', 'id'), 'users_id');
return $this->hasOne(config(config('magicklink.auth_provider').'.model'), config('magiclink.user_primarykey', 'id'), 'users_id');
}
}
15 changes: 15 additions & 0 deletions src/config/magiclink.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Application auth provider
|--------------------------------------------------------------------------
|
| By default users is auth provider (can be found at config/auth with providers key).
| If you want magick link for other auth guard you can change that here.
|
|
*/

'auth_provider' => 'users',

'auth_guard' => 'web',

/*
|--------------------------------------------------------------------------
| Application magiclink Table
Expand Down