Skip to content

Commit

Permalink
#56 - try again to fix the safari sign in bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Apr 19, 2021
1 parent 698ea00 commit 7b00cff
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 38 deletions.
6 changes: 6 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Laravel\Socialite\Two\InvalidStateException;
use Symfony\Component\HttpFoundation\Response;
use Throwable;

class Handler extends ExceptionHandler
Expand Down Expand Up @@ -35,5 +37,9 @@ public function register(): void
$this->reportable(function (Throwable $e) {
//
});

$this->renderable(function (InvalidStateException $e): Response {
return response()->view('errors.oauth_state');
});
}
}
26 changes: 17 additions & 9 deletions app/Http/Controllers/Auth/GithubController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,14 @@
use Illuminate\Support\Facades\Bus;
use Laravel\Socialite\Two\GithubProvider;
use Laravel\Socialite\Facades\Socialite;
use Laravel\Socialite\Two\InvalidStateException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

class GithubController
{
public function __invoke(): Response
{
try {
$githubUser = $this->socialite()->user();
} catch (InvalidStateException $ex) {
return redirect()->route('home');
}
$githubUser = $this->socialite()->user();

$data = [
'email' => $githubUser->getEmail(),
Expand Down Expand Up @@ -53,9 +48,22 @@ public function __invoke(): Response
*/
Auth::login($user, false);

return redirect()->intended(
route('home')
)->setStatusCode(200); // https://github.com/Astrotomic/opendor.me/issues/56
// https://github.com/Astrotomic/opendor.me/issues/56
$redirectTo = url(session()->pull('url.intended', route('home')));

return response(<<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="refresh" content="1;url=$redirectTo" />
<title>Redirecting to $redirectTo</title>
</head>
<body>
Redirecting to <a href="$redirectTo">$redirectTo</a>.
</body>
</html>
HTML);
}

public function redirect(): RedirectResponse
Expand Down
22 changes: 22 additions & 0 deletions resources/views/components/layout/error.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<x-layout.web class="flex flex-col flex-grow justify-center bg-white">

<div class="py-12 px-4 mx-auto max-w-7xl text-center sm:px-6 lg:py-16 lg:px-8">
{{ $slot }}

<div class="flex justify-center mt-12">
<div class="inline-flex rounded-md shadow">
<a href="{{ url('/') }}" class="inline-flex justify-center items-center py-3 px-5 space-x-2 text-base font-medium text-white bg-brand-600 rounded-md border border-transparent hover:bg-brand-700">
<x-far-home class="w-4 h-4 text-gray-100"/>
<span>back home</span>
</a>
</div>
<div class="inline-flex ml-3">
<a href="https://github.com/Astrotomic/opendor.me/issues/new?labels=bug" class="inline-flex justify-center items-center py-3 px-5 space-x-2 text-base font-medium text-gray-700 bg-gray-100 rounded-md border border-transparent hover:bg-gray-200">
<x-far-bug class="w-4 h-4 text-gray-500"/>
<span>report bug</span>
</a>
</div>
</div>
</div>

</x-layout.web>
39 changes: 10 additions & 29 deletions resources/views/errors/404.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,15 @@
@endenv
@endpush

<x-layout.web class="flex flex-col flex-grow justify-center bg-white">
<x-layout.error>
<x-fal-ghost class="mx-auto w-24 h-24 text-gray-400"/>

<div class="py-12 px-4 mx-auto max-w-7xl text-center sm:px-6 lg:py-16 lg:px-8">
<x-fal-ghost class="mx-auto w-24 h-24 text-gray-400"/>

<div class="mt-6 space-y-2">
<h1 class="text-3xl font-extrabold tracking-tight text-gray-900 uppercase sm:text-4xl">
Error <span class="text-gray-400">404</span>
</h1>
<h2 class="text-2xl font-extrabold tracking-tight text-gray-900 sm:text-3xl">
Page Not Found
</h2>
</div>

<div class="flex justify-center mt-12">
<div class="inline-flex rounded-md shadow">
<a href="{{ url('/') }}" class="inline-flex justify-center items-center py-3 px-5 space-x-2 text-base font-medium text-white bg-brand-600 rounded-md border border-transparent hover:bg-brand-700">
<x-far-home class="w-4 h-4 text-gray-100"/>
<span>back home</span>
</a>
</div>
<div class="inline-flex ml-3">
<a href="https://github.com/Astrotomic/opendor.me/issues/new?labels=bug&template=bug-report.md" class="inline-flex justify-center items-center py-3 px-5 space-x-2 text-base font-medium text-gray-700 bg-gray-100 rounded-md border border-transparent hover:bg-gray-200">
<x-far-bug class="w-4 h-4 text-gray-500"/>
<span>report bug</span>
</a>
</div>
</div>
<div class="mt-6 space-y-2">
<h1 class="text-3xl font-extrabold tracking-tight text-gray-900 uppercase sm:text-4xl">
Error <span class="text-gray-400">404</span>
</h1>
<h2 class="text-2xl font-extrabold tracking-tight text-gray-900 sm:text-3xl">
Page Not Found
</h2>
</div>

</x-layout.web>
</x-layout.error>
20 changes: 20 additions & 0 deletions resources/views/errors/oauth_state.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@push('javascript')
@env('frosty-pond', 'divine-forest')
<script nonce="{{ csp_nonce() }}">
window.plausible("404", { props: { path: document.location.pathname } })
</script>
@endenv
@endpush

<x-layout.error>
<x-fal-alien-monster class="mx-auto w-24 h-24 text-gray-400"/>

<div class="mt-6 space-y-2">
<h1 class="text-3xl font-extrabold tracking-tight text-gray-900 uppercase sm:text-4xl">
Error <span class="text-gray-400">424</span>
</h1>
<h2 class="text-2xl font-extrabold tracking-tight text-gray-900 sm:text-3xl">
Invalid oAuth State
</h2>
</div>
</x-layout.error>

0 comments on commit 7b00cff

Please sign in to comment.