/// Get the user's identity. Refresh it if necessary.
Get the user's identity. Refresh it if necessary.
Get the user ' s identity . Refresh it if necessary .
pub async fn identity(&self) -> Option<AuthenticationCookie> {
        // Get the inner identity as a String.
        let id: String = self.inner.identity()?;
        // try to deserialize it
        match serde_json::from_str::<AuthenticationCookie>(id.as_str()) {
            // On okay, refresh the identity cookie if needed
            Ok(id) => match id.refresh().await {
                // If this succeeds
                Ok(id) => {
                    // Save and return the authenticated identity
                    self.save(&id);
                    return Some(id);
                }
                // If it fails to refresh, we have no identity. Send a warning
                // and return None.
                Err(e) => {
                    warn!("Could not refresh identity token. Error: {}", e);
                    return None;
                }
            },
            // If there is an error deserializing, the identity is malformed.
            // Forget it, and log a warning. Return no identity.
            Err(err) => {
                warn!("Bad identity forgotten. Error: {}", err);
                self.forget();
                return None;
            }
        }
    }
pub async fn identity ( & self ) -> Option < AuthenticationCookie > { // Get the inner identity as a String. let id : String = self . inner . identity ( ) ? ; // try to deserialize it match serde_json :: from_str :: < AuthenticationCookie > ( id . as_str ( ) ) { // On okay, refresh the identity cookie if needed Ok ( id ) => match id . refresh ( ) . await { // If this succeeds Ok ( id ) => { // Save and return the authenticated identity self . save ( & id ) ; return Some ( id ) ; } // If it fails to refresh, we have no identity. Send a warning // and return None. Err ( e ) => { warn ! ( " " e ) ; return None ; } } , // If there is an error deserializing, the identity is malformed. // Forget it, and log a warning. Return no identity. Err ( err ) => { warn ! ( " " err ) ; self . forget ( ) ; return None ; } } }
Get the user's identity.
Get the user ' s identity .
&self