I'm writing an hybrid application on Intel xdk platform and laravel 5.2.* as server side. The thing is that when i'm logging in with Auth::login() i return response json to the external client applicatiopn an then keep sending ajax request, but the post-login ajax request generate different session and thus my Auth::user() is being lost. It is very important to clarify that the client application in this situation (hybrid application) running on the mobile and the server application running on my company server. Helpful suggestions will be embraced with great gratitude, because I'm trying to solve this issue over the past 2 days. This is the AuthController where the login is occuring:
public function postLogin()
{
try
{
$user = User::whereUsername(Request::input('username'))->first();
if(count($user) <= 0)
throw new Exception("שם משתמש לא קיים");
if(!$this->check_password($user,Request::input('password')))
throw new Exception("הזנת סיסמא שגויה");
Auth::login($user);
return response()->json(['success' => 'OK']);
}
catch(Exception $e)
{
return response()->json(['error' => $e->getMessage()]);
}
}
This is the clientController where i need the lost Auth:user()
public function fetch($query)
{
return Client::whereGroup_id(Auth::user()->parent_id)
->whereDeleted(0)
->orWhere("first_name", "like", '%$query')
->orWhere("last_name", "like", '%$query')
->orWhere("passport", "like", "%$query%")
->get();
}
This is the first ajax request for the login from the client:
$.ajax({
url: "http://localhost:86/auth/login",
type: "POST",
data:{username:$('#username').val(),password:$('#password').val()},
success: function(result){
if(result.success)
{
af.ui.loadContent("#client_page",false,false,"fade");
}
}
});
And finally the post-login ajax requests coming from typeahead element u can see the called url at the remote filed:
$(document).ready(function(){
var name_randomizer = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
// You can also prefetch suggestions
// prefetch: 'data/typeahead-generate.php',
// remote: "http://" + connection.getHost() + ":" + connection.getPort() + "/admin/fetch/%QUERY"
remote: "http://" + connection.getHost() + ":" + connection.getPort() + "/fetch/%QUERY"
});
name_randomizer.initialize();
$('#client_search').typeahead({
hint: true,
highlight: true
}, {
name: 'string-randomizer',
displayKey: 'value',
source: name_randomizer.ttAdapter()
});
});