화면 캡처에서 sub
(제목)은 user_id
입니다. 예상 한 user_id
이 facebook|1
이 될지 확인하십시오.
당신은 여기
const userId = JSON.parse(userInfo)['sub'];
를 사용하여 문자열 JSON 개체를 구문 분석 할 필요가 작동되는 샘플 :
var AuthenticationClient = require('auth0').AuthenticationClient;
var auth0 = new AuthenticationClient({
domain: '{TENANT}.auth0.com',
clientId: '{client id}'
});
const accessToken = '{access token}';
auth0.getProfile(accessToken, function (err, userInfo) {
const userId = JSON.parse(userInfo)['sub'];
console.log(userId);
});
참고 만을 - 당신이 sub
라고 할 때, String 객체를 처리하고 있기 때문에 당신은 더 이상 사용되지 않는 것에 대한 참조를 얻고있었습니다 String sub
prototype function 혼란을 이해할 수 있습니다. 어떤 유형의 객체인지 확실하지 않으면 좋은 방법은 다음과 같습니다. console.log(typeof userInfo);
문제를 해결하는 데 도움이된다면 제 대답을 확인해 주시겠습니까? :) – arcseldon