private void RestoreSessionAndConnect()
    {
        // Lets check if we can restore a cached session.
        var sessionString = PlayerPrefs.GetString("nk.session");

        if (string.IsNullOrEmpty(sessionString))
        {
            return;             // We have no session to restore.
        }

        var session = NSession.Restore(sessionString);

        if (session.HasExpired(DateTime.UtcNow))
        {
            return;             // We can't restore an expired session.
        }

        SessionHandler(session);
    }
Esempio n. 2
0
        // Restore serialised session token from PlayerPrefs
        // If the token doesn't exist or is expired `null` is returned.
        private static INSession RestoreSession()
        {
            var cachedSession = PlayerPrefs.GetString("nk.session");

            if (string.IsNullOrEmpty(cachedSession))
            {
                Logger.Log("No Session in PlayerPrefs.");
                return(null);
            }

            var session = NSession.Restore(cachedSession);

            if (!session.HasExpired(DateTime.UtcNow))
            {
                return(session);
            }
            Logger.Log("Session expired.");
            return(null);
        }