my question is quite simple : how sp_session_relogin is working ?
Here is how I try to use it.
bool login(const char* login, const char* password, bool remember)
{
if (remember) {
sp_error err = sp_session_relogin(_session);
if (err==SP_ERROR_OK) {
return true;
}
if (!login||!password) {
return false;
}
}
sp_session_login(_session, login, password, remember, NULL);
return true;
}
and I my application I first call
login(0,0,true);
and if it returns false I recall it like this
login(username,password,true);
(username and password are retrieved from a UI).
then if I quite the application and relaunched it the first call to login continue to return false.
Edited after the answer from iKenndac
I was calling sp_session_logout() but I was not waiting for the logout callback being called. I had it but it is not better.
Here is how my application is ending
if (_session) {
if (_loggedin) {
char buffer[1024];
int ret = sp_session_remembered_user(_session,buffer,sizeof(buffer));
if (ret>0) {
printf("remembered user: %s\n",buffer);
}
sp_session_logout(_session);
int msTilNext = 0;
while(_loggedin) {
sp_session_process_events(_session, &msTilNext);
}
}
sp_session_release(_session);
_session = 0;
}
sp_session_remembered_user correctly return my username. After logout I am waiting for the logout callback being called processing event with sp_session_process_events. When logout callback is called, _loggedin became false so the loop end. I release the session. And quite the application.
Do you see another mistake or missing stuff ? Any idea ?
Thanks.
When you quit your application, make sure you call
sp_session_logout()and wait until the logout completion callback is fired before allowing the application to terminate. Otherwise you’re likely to get an incomplete cache which will causesp_session_relogin()to fail.