refactor: change mobile-token to mobile-auth-token

v2.0.0
ricky rx 2 years ago
parent 2c1a415979
commit b6e3edecde

@ -3,7 +3,7 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
MOBILE_TOKEN=Gaobd5OKPdGARLGTD03vSFStrADAxmQ9
MOBILE_AUTH_TOKEN=Gaobd5OKPdGARLGTD03vSFStrADAxmQ9
# for CORS
SANCTUM_STATEFUL_DOMAINS=[http://localhost:3000]

@ -14,11 +14,12 @@ class MobileMiddleware
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response {
$serverMobileToken = env('MOBILE_TOKEN', '');
if(!$serverMobileToken) throw new \Exception('Mobile token in server is not found');
$serverMobileAuthToken = env('MOBILE_AUTH_TOKEN', '');
if(!$serverMobileAuthToken) throw new \Exception('Mobile Auth token in server is not found');
$clientMobileToken = $request->header('mobile-token', '');
if($serverMobileToken != $clientMobileToken) throw new \Exception('Invalid Mobile Token');
$clientMobileAuthToken = $request->header('mobile-token', '');
if(!$clientMobileAuthToken) $clientMobileAuthToken = $request->header('mobile-auth-token', '');
if($serverMobileAuthToken != $clientMobileAuthToken) throw new \Exception('Invalid Mobile Auth Token');
return $next($request);
}
}

Loading…
Cancel
Save