I am having difficulties to implement a redirect with Laravel 5.6
to a mobile app url.
So the idea is that API
handles a request and based on user agent it redirects to either android
or ios
app.
Controller
/**
* Reset password redirect logic.
* Redirect user to either android or iphone app based on http user agent.
*
* @param RedirectRequest $request
* @return RedirectResponse
*/
public function redirect(RedirectRequest $request): RedirectResponse
{
$email = $request->get('email');
$rememberToken = $request->get('rememberToken');
$userAgent = $request->server('HTTP_USER_AGENT');
if (strpos(strtolower( $userAgent ), 'iphone' ) !== false) {
return redirect()->to(
env('FORGET_PASSWORD_IOS_URL') . '?$email=' . $email . '&rememberToken=' . $rememberToken
);
} else if (strpos(strtolower( $userAgent ), 'android' ) !== false) {
return redirect()->to(
env('FORGET_PASSWORD_ANDROID_URL') . '?$email=' . $email . '&rememberToken=' . $rememberToken
);
}
}
.env
# URL SCHEMA FROM MOBILE APP DEVELOPERS.
FORGET_PASSWORD_IOS_URL=mobileapp://
FORGET_PASSWORD_ANDROID_URL=mobileapp://
So the idea behind this, is that when a user requests a password reset from the mobile app, they get an email and that email will contain a link to api. Once user visits a link, they will be redirected to either android or ios app to continue.
The link user receives in email looks like this. http://api.url.com/password-reset?email=<email>&rememberToken=<TOKEN>
After user visits the url I expect the result to be in the browser.
mobileapp://?email=me@email.com&rememberToken=<TOKEN>
The actual result.
http://api.url.com/mobileapp:?email=me@email.com&rememberToken=<TOKEN>
Anyone encountered this before? Or any advices?