Skip to content

Commit

Permalink
build: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau committed Oct 22, 2023
1 parent 832d921 commit 5b2040c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 7 additions & 5 deletions examples/error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_key_rotation::{
AuthProvider, KeyRotationPlugin, KeyRotationSettings, Keystore,
KeystoreState, StartKeyRotationExt, TokenRotationError,
};
use std::{sync::Arc, time::Duration};
use std::sync::Arc;

pub struct MyAuthProvider;

Expand All @@ -24,9 +24,9 @@ impl AuthProvider for MyAuthProvider {
access_token: "123".to_string(),
refresh_token: "456".to_string(),
access_expires: bevy_key_rotation::Instant::now()
+ Duration::from_secs(20),
+ bevy_key_rotation::Duration::from_secs(20),
refresh_expires: bevy_key_rotation::Instant::now()
+ Duration::from_secs(60),
+ bevy_key_rotation::Duration::from_secs(60),
})
}
async fn refresh(
Expand Down Expand Up @@ -56,8 +56,10 @@ fn status_check(
return;
}

if keystore.access_token_valid_for() < Duration::from_secs(5) {
log::error!("The keystore is about to be non-conformant!");
if keystore.access_token_valid_for()
< bevy_key_rotation::Duration::from_secs(5)
{
log::warn!("The keystore is about to be non-conformant!");
// You could attempt to re-authenticate from scratch:
// commands.start_key_rotation(username, password);
// Or panic, or safe your system and prepare to exit, etc.
Expand Down
9 changes: 5 additions & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_key_rotation::{
AuthProvider, KeyRotationPlugin, KeyRotationSettings, Keystore,
StartKeyRotationExt, TokenRotationError,
};
use std::{sync::Arc, time::Duration};
use std::sync::Arc;

pub struct MyAuthProvider;

Expand All @@ -24,9 +24,9 @@ impl AuthProvider for MyAuthProvider {
access_token: random_token(),
refresh_token: random_token(),
access_expires: bevy_key_rotation::Instant::now()
+ Duration::from_secs(10),
+ bevy_key_rotation::Duration::from_secs(10),
refresh_expires: bevy_key_rotation::Instant::now()
+ Duration::from_secs(20),
+ bevy_key_rotation::Duration::from_secs(20),
})
}
async fn refresh(
Expand All @@ -38,7 +38,8 @@ impl AuthProvider for MyAuthProvider {
password: keystore.password,
access_token: random_token(),
refresh_token: keystore.refresh_token,
access_expires: keystore.access_expires + Duration::from_secs(5),
access_expires: keystore.access_expires
+ bevy_key_rotation::Duration::from_secs(5),
refresh_expires: keystore.refresh_expires,
})
}
Expand Down

0 comments on commit 5b2040c

Please sign in to comment.