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 new refresh token for a user in the database. The token is hashed before storage for security purpsoes.

§Arguments

  • db - A reference to the database connection.
  • user_id - The ID of the user the token belongs to.
  • refresh_token - The refresh token to be stored.
  • expires_at - The expiration time of the refresh token (Unix timestamp).

§Returns

  • Ok(()) if the token was successfully stored.
  • Err if there was an error during the database operation.

§Exmaple

use crate::db::DB;
use crate::db::queries::tokens::store_refresh_token;
let db = DB::new("localhost:8529", "my_database").await.unwrap();
store_refresh_token(&db, "user123", "some_refresh_token", 1700000000).await.unwrap();