nativescript-oauth icon indicating copy to clipboard operation
nativescript-oauth copied to clipboard

Already Logged in

Open ScriptiZer opened this issue 7 years ago • 1 comments
trafficstars

if you are already logged into facebook using device browser of facebook application my application asks me to log in

i think it should use my existing token

ScriptiZer avatar Feb 27 '18 09:02 ScriptiZer

Hi @ScriptiZer .. What I did in my app was to verify if the token is still valid, if it was then I would go to my main screen, if not I would refresh the token or ask for a new login.. Something like this:

if (tnsOAuthModule.instance.tokenResult) {
            console.log('Accesss token expires at: ' + tnsOAuthModule.instance.tokenResult.accessTokenExpiration);
            if (tnsOAuthModule.accessTokenExpired() === true) {
                tnsOAuthModule.instance.refreshToken()
                .then((result: string) => {
                    console.log('SUCCESSFULLY REFRESHED TOKEN!');
                    console.log(result);
                    this.login();
                    
                })
                .catch((er) => {
                    console.log(er);
                    this.ensureToken();
                });
            } else{
                this.login();
            } 
        }
        else{
            this.ensureToken();
        }

lumayara avatar Apr 18 '18 17:04 lumayara