Skip to content

Commit

Permalink
refactor: code dedup
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-shine committed Jan 25, 2024
1 parent 22fa180 commit 2f43a55
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,21 +510,21 @@ where
let client = self.client.as_ref().ok_or(OAuth2Error::NotInitialized)?;
let config = self.config.as_ref().ok_or(OAuth2Error::NotInitialized)?;

let post_login_url = Self::current_url().map_err(OAuth2Error::StartLogin)?;
let current_url = Self::current_url().map_err(OAuth2Error::StartLogin)?;

// take the parameter value first, then the agent configured value, then fall back to the default
let redirect_url = match options.redirect_url.or_else(|| {
config
.options
.as_ref()
.and_then(|opts| opts.redirect_url.clone())
}) {
Some(redirect_url) => redirect_url,
None => Self::current_url().map_err(OAuth2Error::StartLogin)?,
};
let redirect_url = options
.redirect_url
.or_else(|| {
config
.options
.as_ref()
.and_then(|opts| opts.redirect_url.clone())
})
.unwrap_or_else(|| current_url.clone());

if redirect_url != post_login_url {
SessionStorage::set(STORAGE_KEY_POST_LOGIN_URL, post_login_url)
if redirect_url != current_url {
SessionStorage::set(STORAGE_KEY_POST_LOGIN_URL, current_url)
.map_err(|err| OAuth2Error::StartLogin(err.to_string()))?;
}

Expand Down

0 comments on commit 2f43a55

Please sign in to comment.