Skip to content

Commit

Permalink
Cleanup fixes (#53)
Browse files Browse the repository at this point in the history
* Make idToken a property of User (instead of function).
* Remove Client.cachedUser completely.
  • Loading branch information
zamzterz authored Aug 31, 2022
1 parent 9e1d02b commit f5931b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,24 +211,16 @@ class Client : ClientInterface {
}
}

private var cashedUser: User? = null

/** Resume any previously logged-in user session */
override fun resumeLastLoggedInUser(callback: (Either<StorageError, User?>) -> Unit) {
sessionStorage.get(configuration.clientId) { result ->
result
.foreach { storedUserSession: StoredUserSession? ->
if (storedUserSession == null) {
cashedUser = null
callback(Right(null))
} else {
val user = User(this, storedUserSession.userTokens)
if (user.equals(cashedUser)) {
callback(Right(cashedUser))
} else {
cashedUser = user
callback(Right(cashedUser))
}
callback(Right(user))
}
}
.left().foreach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class User {
tokens.idTokenClaims.sub
}

/**
* ID Token
*/
val idToken: String
get() = onlyIfLoggedIn { tokens ->
tokens.idToken
}

constructor(client: Client, session: UserSession) : this(client, session.tokens)

internal constructor(client: Client, tokens: UserTokens) {
Expand Down Expand Up @@ -86,11 +94,6 @@ class User {
client.schibstedAccountApi.userProfile(this, callback)
}

/**
* Get idToken for User
* */
fun getIdToken(): String? = tokens?.idToken

/**
* Generate URL with embedded one-time code for creating a web session for the current user.
*
Expand Down

0 comments on commit f5931b0

Please sign in to comment.