userSession.loadUserData() 中的 userData 与传统的 blockstack.js 方法的工作方式不同。
使用以前的身份验证,我可以let person = new blockstack.Person(userData)
获取浏览器设置的“名称”和“头像”配置文件数据。 IE。 person.name()
和person.avatarUrl()
。
使用连接,上述过程为 person.name() 和 person.avatarUrl() 返回null
,即使它们存在。
对于那些希望允许一些个性化外观的应用程序来说,这是一种回归。
问题是旧版块堆栈浏览器返回从配置文件 url 获取的 authReponse 令牌中的配置文件,而新的块堆栈应用程序/身份验证器不执行此查找。
仍然想要查看用户个人资料的应用程序应该调用查找个人资料(http://blockstack.github.io/blockstack.js/globals.html#lookupprofile)我猜。
loadUserData
仍然这样做,它加载验证器提供的本地缓存(localstorage)中可用的用户数据。
有趣的是,对于请求publish_data
的应用程序,连接身份验证器确实会返回配置文件。
@hstove 是否考虑为单人游戏应用重新添加此支持?
@friedger使用 lookupProfile 仍然无法访问个性化所需的 name() 和 avatarUrl()。
@dantrevino lookupProfile
返回具有属性name
和image[i].contentUrl
如果由用户提供)的配置文件的承诺。
@friedger我没看到。 我错过了什么?
const userData = userSession.loadUserData();
const profile = blockstack.lookupProfile(userData.username);
console.log("profile loaded: ", profile);
profile loaded:
_proto__: Promise
constructor: ƒ Promise()
then: ƒ then()
catch: ƒ catch()
finally: ƒ finally()
Symbol(Symbol.toStringTag): "Promise"
__proto__: Object
<strong i="9">@type</strong>: "Person"
<strong i="10">@context</strong>: "http://schema.org"
apps: {http://localhost:8080: "https://gaia.blockstack.org/hub/1AdqWQnAMsb8uQsrZy96G2P7HYd1zkpMnr/", https://reclaim.gg: "https://gaia.blockstack.org/hub/1PcbTDbgybtTjkETvo9j5jr92VFKJ4rwWC/", https://boom-money-daily.runkodapps.com: "https://gaia.blockstack.org/hub/19wdVbKFyNqVVSuJf8ppt8P92LjUMdJjpz/", https://noteriot-daily.runkodapps.com: "https://gaia.blockstack.org/hub/1Br9sxhdSw6xQJ3x8vvQNkuAz5X5oAq7a5/", https://runkod.com: "https://gaia.blockstack.org/hub/1NpdmvGsNyisR56CUiZHfZHnZukMYiSjJ5/", …}
api: {gaiaHubConfig: {…}, gaiaHubUrl: "https://hub.blockstack.org"}
__proto__:
constructor: ƒ Object()
__defineGetter__: ƒ __defineGetter__()
__defineSetter__: ƒ __defineSetter__()
hasOwnProperty: ƒ hasOwnProperty()
__lookupGetter__: ƒ __lookupGetter__()
__lookupSetter__: ƒ __lookupSetter__()
isPrototypeOf: ƒ isPrototypeOf()
propertyIsEnumerable: ƒ propertyIsEnumerable()
toString: ƒ toString()
valueOf: ƒ valueOf()
toLocaleString: ƒ toLocaleString()
get __proto__: ƒ __proto__()
set __proto__: ƒ __proto__()
有关缺少的配置文件详细信息,请参阅https://github.com/blockstack/ux/issues/322
我已经对身份验证器进行了修复 - 存在一些问题,我们没有在authResponse
之前正确获取配置文件。 请再试一次,如果您看到相同的问题,请告诉我。
@hstove仅供参考,使用类方法仍然无法正常工作。 我已经确保我的个人资料有一个名字和头像:
https://gaia.blockstack.org/hub/1JE8MjzuSi19cBifCvrbsyAjx8PvwhakZp/profile.json
我的登录方法:
signIn() {
const authOptions = {
// The URL you want the user to be redirected to after authentication.
redirectTo: "/wallet",
manifestPath: "/manifest.json",
sendToSignIn: true,
finished: ({ userSession }) => {
this.logInUser(userSession);
},
appDetails: {
name: "Boom.Webby",
icon: `${location.origin}/app-icon.png`,
},
};
authenticate(authOptions);
},
登录用户():
logInUser(context, session) {
console.log("user session: ", session);
let userData = session.loadUserData();
let person = new blockstack.Person(userData);
userData.name = person.name();
userData.avatar = person.avatarUrl();
userData.authenticated = true;
console.log("userData: ", userData);
context.dispatch("setUser", userData);
},
和 console.log() 的输出 .. 注意名称和头像在使用类方法时仍然是null
:
{username: "fibonacci.id", profile: {…}, email: null, decentralizedID: "did:btc-addr:1JE8MjzuSi19cBifCvrbsyAjx8PvwhakZp", identityAddress: "1JE8MjzuSi19cBifCvrbsyAjx8PvwhakZp", …}
appPrivateKey: (...)
authResponseToken: (...)
authenticated: (...)
avatar: null
coreSessionToken: (...)
decentralizedID: (...)
email: (...)
gaiaAssociationToken: (...)
hubUrl: (...)
identityAddress: (...)
name: null
profile: (...)
username: (...)
但是,当我查看本地存储中的blockstack-session
时,名称和图像道具就在那里。
userData: {username: "fibonacci.id", profile: {<strong i="21">@type</strong>: "Person", <strong i="22">@context</strong>: "http://schema.org",…}, email: null,…}
appPrivateKey: "..."
.
.
.
profile: {<strong i="23">@type</strong>: "Person", <strong i="24">@context</strong>: "http://schema.org",…}
.
.
.
image: [{<strong i="25">@type</strong>: "ImageObject", name: "avatar",…}]
name: "Fibonacci"
username: "fibonacci.id"
version: "1.0.0"
我没看到。 我错过了什么?
@dantravino这里的问题是lookupProfile
返回一个 Promise,而您没有使用await
。 所以,你得到的是一个 Promise。
感谢您跟进使用Person
类时仍然存在的问题 - 我会研究一下。
嘿@dantravino - 看起来你只需要调用new Person(userData.profile)
,而不是new Person(userData)
。 也许它以前对你有不同的作用? 但这与此处的文档一致:
https://blockstack.github.io/blockstack.js/index.html#quickstart -build-an-application