Skip to content

Commit

Permalink
Merge pull request #293 from mycookbook/quick-fix-tiktok-login
Browse files Browse the repository at this point in the history
implement uri helper util class
  • Loading branch information
fokosun authored Oct 7, 2023
2 parents bcc64a4 + e2e7664 commit f2e5748
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=UTC
APP_URL=http://localhost:8000
VUE2_APP_URL=https://web.cookbookshq.com/#/

DB_HOST=
DB_PORT=
Expand Down
31 changes: 17 additions & 14 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
use App\Services\AuthService;
use App\Services\LocationService;
use App\Services\UserService;
use App\Utils\UriHelper;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;
use Tymon\JWTAuth\Exceptions\JWTException;
Expand Down Expand Up @@ -240,25 +242,26 @@ public function tikTokHandleCallback(Request $request, Client $client, UserServi
$userInfo['data']['user']['video_count']
));

$to = 'https://web.cookbookshq.com/#/tiktok/?' . http_build_query([
'token' => $token,
'_d' => $user->getSlug(),
]);
$to = UriHelper::buildHttpQuery('tiktok', ['token' => $token, '_d' => $user->getSlug()]);

return redirect($to);
return UriHelper::redirectToUrl($to);
} else {
return redirect('https://web.cookbookshq.com/#/errors/?m=Hey, it looks like your tiktok account is Private. Please login using a public account.');
return UriHelper::redirectToUrl(
UriHelper::buildHttpQuery(
'errors',
['m' => Lang::get('errors.login.tiktok.private_account')]
)
);
}
} catch (\Exception $e) {
Log::debug(
'Tiktok Login error',
[
'errorCode' => $errCode,
'errorMsg' => $e->getMessage()
]
);
Log::debug('Tiktok Login error', ['errorCode' => $errCode, 'errorMsg' => $e->getMessage()]);

return redirect("https://web.cookbookshq.com/#/errors/?m=We are experiencing some technical difficulty logging you in with TikTok, please try again.");
return UriHelper::redirectToUrl(
UriHelper::buildHttpQuery(
'errors',
['m' => Lang::get('errors.login.tiktok.generic')]
)
);
}
}

Expand Down
18 changes: 18 additions & 0 deletions app/Utils/UriHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Utils;

class UriHelper
{
public static function buildHttpQuery(string $redirectTo, array $parameters): string
{
return config('services.redirects.' . $redirectTo) . http_build_query($parameters);
}

public static function redirectToUrl($to)
{
return redirect($to);
}
}
9 changes: 4 additions & 5 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@
'ipinfo' => [
'access_token' => env('IPINFO_SECRET', '')
],
'web_urls' => [
'auth' => env('WEB_URL') . '/#/auth?',
'signin' => env('WEB_URL') . '/#/signin?',
'errors' => env('WEB_URL') . '/#/errors?',
],
'faker' => [
'pass' => env('MAGICLINK_PASS')
],
'otp' => [
'digits' => 6,
'validity' => 15 //mins
],
'redirects' => [
'tiktok' => env('VUE2_APP_URL') . 'tiktok/?',
'errors' => env('VUE2_APP_URL') . 'errors/?',
]
];
10 changes: 10 additions & 0 deletions resources/lang/en/errors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'login' => [
'tiktok' => [
'generic' => 'We are experiencing some technical difficulty logging you in with TikTok, please try again.',
'private_account' => 'Hey, it looks like your tiktok account is Private. Please login using a public account.'
]
],
];

0 comments on commit f2e5748

Please sign in to comment.