Giter Site home page Giter Site logo

Error After Adding OTP about laravel-auth HOT 3 CLOSED

cjmellor avatar cjmellor commented on July 3, 2024
Error After Adding OTP

from laravel-auth.

Comments (3)

bjrnblm avatar bjrnblm commented on July 3, 2024 1

I ran into the same thing, i think the actual issue is in the laravel-auth-bladebones package:

https://github.com/claudiodekker/laravel-auth-bladebones/blob/master/templates/Controllers/Challenges/MultiFactorChallengeController.bladetmpl#L55-L64

Should be:

/**
* Handle an incoming multi-factor challenge confirmation request.
*
* {!! '@' !!}param  \Illuminate\Http\Request  $request
* {!! '@' !!}return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
*/
public function store(Request $request): JsonResponse|RedirectResponse
{
    return parent::store($request);
}

Or

/**
* Handle an incoming multi-factor challenge confirmation request.
*
* {!! '@' !!}param  \Illuminate\Http\Request  $request
* {!! '@' !!}return mixed
*/
public function store(Request $request): mixed
{
    return parent::store($request);
}

Or since its the blade driver, its better to remove the JsonResponse from the store and sendAuthenticatedResponse method completely and only return RedirectResponse? 🤔

Workaround for projects using the laravel-auth-bladebones package is to overwrite the store method in your app App\Http\Controllers\Auth\Challenges\MultiFactorChallengeController:

/**
 * Handle an incoming multi-factor challenge confirmation request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
 */
public function store(Request $request): JsonResponse|RedirectResponse
{
    return parent::store($request);
}

from laravel-auth.

cjmellor avatar cjmellor commented on July 3, 2024

I took a gamble on which repo to post the issue in... guess I picked the wrong one

from laravel-auth.

claudiodekker avatar claudiodekker commented on July 3, 2024

You're absolutely right, definitely an issue with the bladebones package!

To fix it for your app, you should be able to simply add the return type within your app, but I'll make sure to adjust this within the boilerplating once the "proper" laravel-auth-blade package is done (aimed for later this week)

Essentially, what's happening is that this part is providing a RedirectResponse return object:
https://github.com/claudiodekker/laravel-auth-bladebones/blob/master/templates/Controllers/Challenges/MultiFactorChallengeController.bladetmpl#L95-L97

    /**
     * Sends a response indicating that the user has been successfully authenticated.
     *
     * {!! '@' !!}param  \Illuminate\Http\Request  $request
     * {!! '@' !!}param  \Illuminate\Contracts\Auth\Authenticatable  $user
     * {!! '@' !!}param  string  $intendedUrl
     * {!! '@' !!}return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
     */
    protected function sendAuthenticatedResponse(Request $request, Authenticatable $user, string $intendedUrl): JsonResponse|RedirectResponse
    {
        Session::flash('status', __('laravel-auth::auth.success'));

+       if (! $request->wantsJson()) {
+           return redirect()->to($intendedUrl);
+       }

        return new JsonResponse([
            'redirect_url' => $intendedUrl,
        ], 200);
    }

Which is then returned back up the tree, and back up to the store method, which then throws an error due to mismatched return types.

The strict and less strict (yet both 100% valid and correct) fix to this is essentially what @bjrnblm suggested in the first part of their previous comment: Either add the RedirectResponse return type as a compound, or replace the return type with mixed (or remove it altogether if you don't really care about types).

from laravel-auth.

Related Issues (8)

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.