Skip to content

Commit

Permalink
refactor(term): rename jwt_decoder to jwt_service
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Mar 17, 2024
1 parent 98b57a1 commit fa6f178
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/synd_term/src/application/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl JwtService {

pub struct Authenticator {
pub device_flows: DeviceFlows,
pub jwt_decoders: JwtService,
pub jwt_service: JwtService,
}

impl Authenticator {
Expand All @@ -32,7 +32,7 @@ impl Authenticator {
github: DeviceFlow::new(provider::Github::default()),
google: DeviceFlow::new(provider::Google::default()),
},
jwt_decoders: JwtService::new(),
jwt_service: JwtService::new(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/synd_term/src/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ impl Application {
}
}

pub fn jwt_decoders(&self) -> &JwtService {
&self.authenticator.jwt_decoders
pub fn jwt_service(&self) -> &JwtService {
&self.authenticator.jwt_service
}

pub fn set_credential(&mut self, cred: Credential) {
Expand Down
4 changes: 2 additions & 2 deletions crates/synd_term/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ fn cred_file() -> PathBuf {
config::cache_dir().join("credential.json")
}

pub async fn credential_from_cache(jwt_decoders: &JwtService) -> Option<Credential> {
Credential::restore_from_path(cred_file().as_path(), jwt_decoders)
pub async fn credential_from_cache(jwt_service: &JwtService) -> Option<Credential> {
Credential::restore_from_path(cred_file().as_path(), jwt_service)
.inspect_err(|err| {
tracing::error!("Restore credential from cache: {err}");
})
Expand Down
4 changes: 2 additions & 2 deletions crates/synd_term/src/cli/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ impl ExportCommand {

async fn export(self, endpoint: Url) -> anyhow::Result<()> {
let mut client = Client::new(endpoint, Duration::from_secs(10))?;
let jwt_decoders = JwtService::new();
let jwt_service = JwtService::new();

let credentials = auth::credential_from_cache(&jwt_decoders)
let credentials = auth::credential_from_cache(&jwt_service)
.await
.ok_or_else(|| anyhow!("You are not authenticated, try login in first"))?;
client.set_credential(credentials);
Expand Down
2 changes: 1 addition & 1 deletion crates/synd_term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async fn main() {
Application::new(terminal, client).with_theme(Theme::with_palette(&palette.into()))
};

if let Some(auth) = auth::credential_from_cache(app.jwt_decoders()).await {
if let Some(auth) = auth::credential_from_cache(app.jwt_service()).await {
info!("Use authentication cache");
app.set_credential(auth);
}
Expand Down

0 comments on commit fa6f178

Please sign in to comment.