Skip to content

Commit

Permalink
use the id for the token so we persist it
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Oct 25, 2023
1 parent d81dc1a commit 86e6813
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 7 additions & 11 deletions src/Support/URL.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace TransformStudios\Review\Support;

use Statamic\Entries\Entry;
use Statamic\Facades\Token as TockenFacade;
use Statamic\Facades\Token as TokenFacade;
use Statamic\Tokens\Token;
use TransformStudios\Review\TokenHandler;

Expand All @@ -12,16 +12,12 @@ class URL
public static function reviewUrl(Entry $entry): string
{
/** @var \Statamic\Tokens\Token */
$token = tap(
TockenFacade::make(
token: null,
handler: TokenHandler::class,
data: ['id' => $entry->id()]
),
fn (Token $token) => $token
->expireAt(now()->addMonths(6))
->save()
);
if (! $token = TokenFacade::find($entry->id())) {
$token = tap(
TokenFacade::make($entry->id(), TokenHandler::class),
fn (Token $token) => $token->expireAt(now()->addMonths(6))->save()
);
}

return $entry->absoluteUrl().'?token='.$token->token();
}
Expand Down
4 changes: 3 additions & 1 deletion src/TokenHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class TokenHandler
public function handle(Token $token, $request, Closure $next)
{
/** @var \Statamic\Entries\Entry */
$entry = EntryFacade::find($token->get('id'));
if (! $entry = EntryFacade::find($token->token())) {
return $next($request);
}

if ($this->isLive($entry)) {
return redirect($entry->url());
Expand Down

0 comments on commit 86e6813

Please sign in to comment.