GithubHelp home page GithubHelp logo

renoki-co / hej Goto Github PK

View Code? Open in Web Editor NEW
132.0 7.0 13.0 163 KB

Hej! is a simple authentication boilerplate for Socialite.

License: Apache License 2.0

PHP 100.00%
php laravel package packages socialite social github google facebook twitter

hej's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar henirk avatar laravel-shift avatar rennokki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hej's Issues

SocialController not redirecting

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?

`getSocialById()` always return null when implementing `enforceMorphMap`

Background

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 google xxx NULL Imam Susanto xxx xxx xxx xxx

notice on model_type is stored as User not App\Models\User.

Issue

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

Investigation

  1. Error happens on callback handler in controller.
  2. Logic flow should happen inside this https://github.com/renoki-co/hej/blob/master/src/Concerns/HandlesSocialRequests.php#L116
  3. It seems $model is null caused by getModelBySocialId return null
  4. getModelBySocialId is `null caused by https://github.com/renoki-co/hej/blob/master/src/Concerns/HandlesSocialRequests.php#L211
  5. 'getSocialId` is null caused by https://github.com/renoki-co/hej/blob/master/src/Concerns/HandlesSocialRequests.php#L230

Solution

Maybe this can help https://laravel.com/docs/9.x/eloquent-relationships#custom-polymorphic-types

[Proposal] Rearrange how the redirect is implemented

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 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.