renoki-co / hej Goto Github PK
View Code? Open in Web Editor NEWHej! is a simple authentication boilerplate for Socialite.
License: Apache License 2.0
Hej! is a simple authentication boilerplate for Socialite.
License: Apache License 2.0
Hello! ๐๐ป
Maybe it's a misconfiguration on my part, but Hej doesn't redirect to provider ๐
I've been checking RenokiCo\Hej\Http\Controllers\SocialController
, and apparently @redirect
and @callback
are not present, however I did find them in Concerns\HandlesSocialRequests.php
๐ค
Could it be a mistake?
In my application, I'm using enforceMorphmap
// AppServiceProvider.php
public function boot()
{
Relation::enforceMorphMap([
'User' => \App\Models\User::class,
]);
}
because of that, the data on socials
table will be like this
id | model_type | model_id | provider | provider_id | provider_nickname | provider_name | provider_email | provider_avatar | created_at | updated_at |
---|---|---|---|---|---|---|---|---|---|---|
1 | User | 1 | xxx | NULL | Imam Susanto | xxx | xxx | xxx | xxx |
notice on model_type
is stored as User not App\Models\User.
Expected
When I want to login via oauth and socials table already filled with same email with login.
User should be automatically login.
Actual
SQL error unique email (since I setup my database email column as unique index). It means the application is trying to create new user instead of automatically login
callback
handler in controller.$model
is null
caused by getModelBySocialId
return null
getModelBySocialId
is `null caused by https://github.com/renoki-co/hej/blob/master/src/Concerns/HandlesSocialRequests.php#L211Maybe this can help https://laravel.com/docs/9.x/eloquent-relationships#custom-polymorphic-types
Currently, the redirect logic is handled in the SocialController
and always returns Redirect::route('home')
. This causes some problems for apps who don't have a route named home
. Ofc you can always override the SocialController
class and write your own redirect response, but I think it would be a better user experience (for the developer) if the redirection logic is a bit more flexible by default.
If we take the login request then we could take the same approach that laravel/ui
has taken for the redirect. That d mean that instead of calling authenticated()
before authenticateModel()
, we would call it afterwards.
// login logic
$social = $this->updateSocialInstance($request, $provider, $model, $providerUser);
$this->authenticateModel($model);
if ($response = $this->authenticated($request, $model, $social, $providerUser)) {
return $response;
}
return redirect()->intended($this->redirectPath());
// redirectPath
protected function redirectPath()
{
if (method_exists($this, 'redirectTo')) {
return $this->redirectTo();
}
return property_exists($this, 'redirectTo') ? $this->redirectTo : route('home');
}
That way we could utilize the alreadyt existent registered
, authenticated
, linked
and unlinked
methods to do custom redirects if required.
Would you be open to a PR which would make the necessary changes to the codebase @rennokki ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.