Ok, thanks. Well, I think my example is broken and doesn’t correctly handle this scenario. This is the relevant code from the example:
local function login(client)
-- restore a session
local session = nakama_session.restore()
local success = true
if session and nakama_session.is_token_expired_soon(session) and not nakama_session.is_refresh_token_expired(session) then
log("Session has expired or is about to expire. Refreshing.")
success = refresh_session(client, session)
elseif not session or nakama_session.is_refresh_token_expired(session) then
log("Session does not exist or it has expired. Must reauthenticate.")
success = email_login(client, "bjorn@defold.se", "foobar123", "britzl")
else
client.set_bearer_token(session.token)
end
return success
end
And it seems like it fails here:
success = refresh_session(client, session)
This means that there is a stored session which has expired, but has a non-expired refresh token. The problem in this case is that the stored session is linked to a deleted user. The solution should be to change the login function to do a fresh login if the refresh fails. Like this (untested!):
local function login(client)
-- restore a session
local session = nakama_session.restore()
-- use existing session token if it exists and doesn't expire soon
if session and not nakama_session.is_token_expired_soon(session) then
log("Session is good to use!")
client.set_bearer_token(session.token)
return true
end
-- if existing session token is about to expire we need to refresh it
if session and nakama_session.is_token_expired_soon(session) and not nakama_session.is_refresh_token_expired(session) then
log("Session has expired or is about to expire. Refreshing.")
local success = refresh_session(client, session)
-- session was refreshed, early-out!
if success then
log("Session was successfully refreshed!")
return true
end
end
-- if no session token exists or it has expired we need to log in again
log("Session does not exist or it has expired. Must reauthenticate.")
local success = email_login(client, "bjorn@defold.se", "foobar123", "britzl")
return success
end