2017-12-16 4 views
0

Ich benutze auth0. Ich logge mich ein und es geht zurück zur Anmeldeseite. In url, sehe ich dieseauth0 Fehler - nach der Anmeldung, leitet es zurück zur Login-Seite

http://localhost:3000/login#access_token=TecYZ7snyHV-eIHScHWNFm885bR9akp2&expires_in=7200&token_type=Bearer&state=af6AJGNuu726MuTgk6iGUdFBfM4tmtBX&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlJEUTNPVFl6UmpCRE9UQkVSVEZCTWpFek16ZzFOemMxTWtJMVFqazJRelJDTmpFd01UZ3dNdyJ9.eyJpc3MiOiJodHRwczovL2FwcDExNjMuYXV0aDAuY29tLyIsInN1YiI6ImF1dGgwfDVhMzQwYjk0MTk3YzRmNjhmMDA4M2UzYSIsImF1ZCI6IjBaeGhtREtyb2p5YTFqODVrUHNRRWRVZ1hVdm1LZFlyIiwiaWF0IjoxNTEzNDQzOTQ5LCJleHAiOjE1MTYwNzM2OTUsImF0X2hhc2giOiJiU1gxa3Z5ZzJSVEYxVXFLdTV0bDhnIiwibm9uY2UiOiJzWEtoWklxVWxTYUdVMjJfSjJLOF9Hckw4VDQzQWpySCJ9.pfgRCrPuBxMMO6obMkBL_VsCANPFU4LSKYzqXXw_TPKNAYu-qSIQUVnHPtoPMS7NpndgLxWeSvZdQgUMW1oTaDtDLYsbftc8KV-IpFkc269yHcpyMO3TzEczAHLcKT6Y3FpXN5tnnrHxF0wjBSIPh4JNVMkG8AJG4nq3m-uPUuEOQRNvaQGFnFTSJet-H5A5_9aFXVmrH1FmK2LYGGLCJucwOfrC6cV-RqbJRaJ2ZCcqOm3vK08J2bUOBop8Jh7LUoCxoBB480RBmMfqctsVQW9etT2nWft7jCei6ZEo-eE2fGiRbPusq2dVvDMB78ar3KIhplEccGNrbom1fmcMww 

mein Code Hier ist

import history from '../history'; 
import auth0 from 'auth0-js'; 


export default class Auth { 
    auth0 = new auth0.WebAuth({ 
    domain: 'app1163.auth0.com', 
    clientID: '0ZxhmDKrojya1j85kPsQEdUgXUvmKdYr', 
    redirectUri: 'http://localhost:3000/login', 

    responseType: 'token id_token', 
    scope: 'openid' 
    }); 

    constructor() { 
    this.login = this.login.bind(this); 
    this.logout = this.logout.bind(this); 
    this.handleAuthentication = this.handleAuthentication.bind(this); 
    this.isAuthenticated = this.isAuthenticated.bind(this); 
    } 

    login() { 
    this.auth0.authorize(); 
    } 

    handleAuthentication() { 
    this.auth0.parseHash((err, authResult) => { 
     if (authResult && authResult.accessToken && authResult.idToken) { 
     this.setSession(authResult); 
     history.replace('/home'); 
     } else if (err) { 
     history.replace('/home'); 
     console.log(err); 
     alert(`Error: ${err.error}. Check the console for further details.`); 
     } 
    }); 
    } 

    setSession(authResult) { 
    // Set the time that the access token will expire at 
    let expiresAt = JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime()); 
    localStorage.setItem('access_token', authResult.accessToken); 
    localStorage.setItem('id_token', authResult.idToken); 
    localStorage.setItem('expires_at', expiresAt); 
    // navigate to the home route 
    history.replace('/home'); 
    } 

    logout() { 
    // Clear access token and ID token from local storage 
    localStorage.removeItem('access_token'); 
    localStorage.removeItem('id_token'); 
    localStorage.removeItem('expires_at'); 
    // navigate to the home route 
    history.replace('/home'); 
    } 

    isAuthenticated() { 
    // Check whether the current time is past the 
    // access token's expiry time 
    let expiresAt = JSON.parse(localStorage.getItem('expires_at')); 
    return new Date().getTime() < expiresAt; 
    } 
} 

Also, kann mir jemand sagen, was falsch in meinem Code und warum seine zur Login-Seite umgeleitet zurück?

Ich möchte auch wissen, ob ich einloggen konnte oder nicht? Wenn ich die URL überprüfe, sieht es so aus, als ob ich mich erfolgreich eingeloggt habe.

Antwort

1

Sollte nicht Ihre redirectUri = localhost: 3000/home?

+0

ja, vielen dank :) –

Verwandte Themen