PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Solved

Telegram for devdojo/auth

Solved
github170

Nov 25th, 2024 08:15 PM

Devdojo\Auth\Http\Controllers\SocialController::redirect(): Return value must be of type Illuminate\Http\RedirectResponse, string returned

I did composer require socialiteproviders/telegram and got the above error after adding telegram to my /config/devdojo/auth/providers.php

Any ideas?

bobbyiliev

Nov 25th, 2024 10:36 PM

Best Answer

Hi there,

I've not used the Telegram Socialite provider before, this is why it is not listed as one of the supported providers in the Auth package. But as far as I can see here in the Telegram Provider.php#L52, the Telegram provider's redirect() method does not return a proper redirect response but instead returns an HTML string. However the redirect() method in the SocialController in the auth package expects to return an Illuminate\Http\RedirectResponse here: src/Http/Controllers/SocialController.php#L18.

Can you try to modify the redirect method in SocialController to handle the Telegram provider specifically:

public function redirect(Request $request, string $driver): RedirectResponse
{
    $this->dynamicallySetSocialProviderCredentials($driver);

    if ($driver === 'telegram') {
        // For Telegram, the redirect method returns HTML, not a proper redirect response
        return response()->make(
            Socialite::driver($driver)->redirect(),
            200,
            ['Content-Type' => 'text/html']
        );
    }

    return Socialite::driver($driver)->redirect();
}

This will properly return the HTML for Telegram's custom login button.

Let me know if it works.

- Bobby

github170

Nov 25th, 2024 11:45 PM

Thanks, before seeing your reply, I did remove the return type from the devdojo/auth package and it worked, but yours is definitely much more refined.

One other thing I will do is to use your solution in the telegram driver rather than deal with this in SocialController. This way SocialController never needs to know about what telegram is.

Report
1
bobbyiliev

Nov 26th, 2024 12:02 AM

Hey!

Ah yes that is a great idea! Let me know if that works! It might be worth documenting that in the auth package docs in case that anyone else hits the issue in the future.

Happy to hear that you got it working!