Telegram for devdojo/auth
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?
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
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.
















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!