Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement uri helper util class #293

Merged
merged 1 commit into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.'
]
],
];