2017-12-16 14 views
0

auth0을 사용 중입니다. 로그인 한 후 로그인 페이지로 돌아갑니다. URL에, 나는 누군가가 그것 로그인 페이지로 다시 리디렉션 무슨 잘못 내 코드와 이유를 말해 줄 수,이auth0 오류 - 로그인 후 다시 로그인 페이지로 리디렉션됩니다.

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 

여기 그래서 내 코드

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; 
    } 
} 

의 표시?

내가 로그인했는지 여부를 알고 싶습니다. URL을 확인하면 정상적으로 로그인 한 것 같습니다.

답변

1

redirectUri = localhost : 3000/home을 사용해야합니까?

+0

예, 고맙습니다. :) –