pub struct ApiKey {
pub id: i64,
pub user_id: i64,
pub key_hash: String,
pub name: String,
pub last_used_at: Option<i64>,
pub expires_at: Option<i64>,
pub created_at: i64,
pub updated_at: i64,
}Fields§
§id: i64§user_id: i64§key_hash: String§name: String§last_used_at: Option<i64>§expires_at: Option<i64>§created_at: i64§updated_at: i64Implementations§
Source§impl ApiKey
impl ApiKey
Sourcepub fn generate_key() -> String
pub fn generate_key() -> String
Generate a new API key with prefix
Sourcepub async fn create_for_user<D: Database>(
db: &D,
user_id: i64,
name: &str,
expires_at: Option<i64>,
) -> Result<(ApiKey, String)>
pub async fn create_for_user<D: Database>( db: &D, user_id: i64, name: &str, expires_at: Option<i64>, ) -> Result<(ApiKey, String)>
Create a new API key for a user
Sourcepub async fn verify_key<D: Database + ?Sized>(
db: &D,
key: &str,
) -> Result<Option<ApiKey>>
pub async fn verify_key<D: Database + ?Sized>( db: &D, key: &str, ) -> Result<Option<ApiKey>>
Find API key by key string and verify it’s valid
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApiKey
impl RefUnwindSafe for ApiKey
impl Send for ApiKey
impl Sync for ApiKey
impl Unpin for ApiKey
impl UnwindSafe for ApiKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more