Skip to main content

store_refresh_token

Function store_refresh_token 

Source
pub async fn store_refresh_token(
    db: &DB,
    user_id: &str,
    refresh_token: &str,
    expires_at: i64,
) -> Result<(), Box<dyn Error + Send + Sync>>
Expand description

Stores a refresh token in the database for a specific user

§Arguments

  • db - A reference to the database connection
  • user_id - The ID of the user for whom the refresh token is being stored
  • refresh_token - The refresh token string to store
  • expires_at - The expiration time of the refresh token as a Unix timestamp

§Returns

  • Ok(()) - If the refresh token was successfully stored
  • Err(Box<dyn Error>) - An error if the operation failed, such as if there was a database error

§Errors

  • “Failed to store refresh token” - If the database query did not execute successfully, indicating that the refresh token could not be stored

§Example

use crate::db::DB;
use crate::db::queries::auth;
async fn example_store_refresh_token(db: &DB) {
    let user_id = "user_id";
    let refresh_token = "refresh_token_string";
    let expires_at = 1700000000; // Example expiration timestamp
    match auth::store_refresh_token(db, user_id, refresh_token, expires_at).await {
        Ok(()) => println!("Refresh token stored successfully"),
        Err(e) => eprintln!("Error storing refresh token: {}", e),
    }
}