找不到当前用户
Current User not found
更新到 2.2 版后,当我尝试使用 TextToolBar 时,我继续收到“❌ 找不到当前用户”错误。
这是我的设置代码:
Client.config = .init(apiKey: "ajbbcwn5bxms", appId: "64415")
Client.shared.setupUser(token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlci1vbmUifQ.AW1xE4VpjzKTpcj3dEX3eLVeXUAoHtaqCEeqDCHYiuo") { result in
// Do all your requests from here. Reload feeds and etc.
if let currentUser = try? result.get() {
let ContainerViewController = self.storyboard?.instantiateViewController(identifier: "tab") as! UITabBarController
ContainerViewController.tabBar.isTranslucent = false
ContainerViewController.tabBar.barTintColor = #colorLiteral(red: 0.08281194419, green: 0.0896929279, blue: 0.1466576457, alpha: 1)
self.view.window?.rootViewController = ContainerViewController
self.view.window?.makeKeyAndVisible()
} else if let error = result.error {
print("Authorization error:", error)
}
}
尽管我的日志说:
User id: user-one
️ Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlci1vbmUifQ.AW1xE4VpjzKTpcj3dEX3eLVeXUAoHtaqCEeqDCHYiuo
The current user was setupped with id: user-one
问题是User.current
returns一个Client.shared.user as? User
。
流源有 GetStream.User
和 Activity 源组件有自己的 GetStreamActivityFeed.User
和额外的属性。
您需要这样设置用户:
Client.config = .init(apiKey: "ajbbcwn5bxms", appId: "64415")
let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlci1vbmUifQ.AW1xE4VpjzKTpcj3dEX3eLVeXUAoHtaqCEeqDCHYiuo"
guard let currentUserId = token.userId else {
print("Bad token:", token)
return
}
let user = GetStreamActivityFeed.User(name: "John Doe", id: currentUserId)
Client.shared.setupUser(user, token: token) { result in
if let currentUser = try? result.get() {
let ContainerViewController = self.storyboard?.instantiateViewController(identifier: "tab") as! UITabBarController
ContainerViewController.tabBar.isTranslucent = false
ContainerViewController.tabBar.barTintColor = #colorLiteral(red: 0.08281194419, green: 0.0896929279, blue: 0.1466576457, alpha: 1)
self.view.window?.rootViewController = ContainerViewController
self.view.window?.makeKeyAndVisible()
} else if let error = result.error {
print("Authorization error:", error)
}
}
更新到 2.2 版后,当我尝试使用 TextToolBar 时,我继续收到“❌ 找不到当前用户”错误。
这是我的设置代码:
Client.config = .init(apiKey: "ajbbcwn5bxms", appId: "64415")
Client.shared.setupUser(token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlci1vbmUifQ.AW1xE4VpjzKTpcj3dEX3eLVeXUAoHtaqCEeqDCHYiuo") { result in
// Do all your requests from here. Reload feeds and etc.
if let currentUser = try? result.get() {
let ContainerViewController = self.storyboard?.instantiateViewController(identifier: "tab") as! UITabBarController
ContainerViewController.tabBar.isTranslucent = false
ContainerViewController.tabBar.barTintColor = #colorLiteral(red: 0.08281194419, green: 0.0896929279, blue: 0.1466576457, alpha: 1)
self.view.window?.rootViewController = ContainerViewController
self.view.window?.makeKeyAndVisible()
} else if let error = result.error {
print("Authorization error:", error)
}
}
尽管我的日志说:
User id: user-one
️ Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlci1vbmUifQ.AW1xE4VpjzKTpcj3dEX3eLVeXUAoHtaqCEeqDCHYiuo
The current user was setupped with id: user-one
问题是User.current
returns一个Client.shared.user as? User
。
流源有 GetStream.User
和 Activity 源组件有自己的 GetStreamActivityFeed.User
和额外的属性。
您需要这样设置用户:
Client.config = .init(apiKey: "ajbbcwn5bxms", appId: "64415")
let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoidXNlci1vbmUifQ.AW1xE4VpjzKTpcj3dEX3eLVeXUAoHtaqCEeqDCHYiuo"
guard let currentUserId = token.userId else {
print("Bad token:", token)
return
}
let user = GetStreamActivityFeed.User(name: "John Doe", id: currentUserId)
Client.shared.setupUser(user, token: token) { result in
if let currentUser = try? result.get() {
let ContainerViewController = self.storyboard?.instantiateViewController(identifier: "tab") as! UITabBarController
ContainerViewController.tabBar.isTranslucent = false
ContainerViewController.tabBar.barTintColor = #colorLiteral(red: 0.08281194419, green: 0.0896929279, blue: 0.1466576457, alpha: 1)
self.view.window?.rootViewController = ContainerViewController
self.view.window?.makeKeyAndVisible()
} else if let error = result.error {
print("Authorization error:", error)
}
}