javascript-sdk icon indicating copy to clipboard operation
javascript-sdk copied to clipboard

期望提供 User.signInWithAuthData API

Open xixilive opened this issue 7 years ago • 4 comments

OAuth常见场景:

  1. createUserWithAuthData.then(signInUser)
  2. currentUser.connect(AuthData)
  3. findUserByAuthData.then(signInUser)

LC RESTful API目前貌似只提供了前两种场景的解决方案, 没有针对第三种场景的方案.

只有login with username/password, mobile/smscode 等这样的API, 没有找到直接signIn一个User instance的API, 对第三种场景而言, 我目前是使用masterKey去refreshSessionToken来间接实现的, 不知是否能提供更加方便的方式呢? 比如:

User.signInWithAuthData(provider, thirdPartUserID)

xixilive avatar Jan 16 '17 11:01 xixilive

https://leancloud.github.io/javascript-sdk/docs/AV.User.html#.signUpOrlogInWithAuthData

leeyeh avatar Jan 17 '17 02:01 leeyeh

这个接口的逻辑是 upsert , 我的业务场景是这样的:

// on OAuth callback phase
const authData = {...}
User.findByAuthData(authData.provider, authData.uid)
.then(user => {
  if(user){
    return user.signIn() // the key point, how to signIn a user instance without any credentails
  }
  session.authData = authData
  redirectTo('loginView')
})

// on Post login

if(session.authData){
  signedInUser.update({authData})
  session.authData = null
  redirectTo('protectedView')
}

xixilive avatar Jan 17 '17 03:01 xixilive

return user.signIn() // the key point, how to signIn a user instance without any credentails

User.signUpOrlogInWithAuthData 确实是 upsert,并且会返回登录后的 user 实例。这里 return User.signUpOrlogInWithAuthData(authData) 就可以满足你的需求了。

但是我不是很理解的是,既然拿到了 authData,那么直接使用 authData 登录即可(反正是 upsert 一定会成功的),为什么要查一下如果没有这个用户去 loginView 呢?

leeyeh avatar Jan 17 '17 03:01 leeyeh

我的业务场景下, 用户是白名单机制, 不允许通过authData直接创建用户, 你们这个接口作了这样一个假设.

另外我觉得把authData embed在User model中也不是很好, 遇到我这个场景就有点麻烦了. User与OAuth应该可以方便的link/unlink, 而不是add/remove

xixilive avatar Jan 17 '17 04:01 xixilive