You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: global_state.rs
    path of file: ./repos/perseus/examples/demos/auth/src
    
    the code of the file until where you have to start completion: use perseus::{prelude::*, state::GlobalStateCreator};
use serde::{Deserialize, Serialize};

pub fn get_global_state_creator() -> GlobalStateCreator {
    GlobalStateCreator::new().build_state_fn(get_build_state)
}

#[engine_only_fn]
async fn get_build_state() -> AppState {
    AppState 
    
    pub fn detect_state(&self) {
        // If we've checked the login status before, then we should assume the status
        // hasn't changed (we'd change this in a login/logout page)
        if let LoginState::Yes | LoginState::No = *self.state.get() {
            return;
        }

        // See the docs page on authentication to learn how to put something *secure*
        // here This example is NOT production-safe, and would result in
        // absolutely terrible security!!!

        // All we're doing in here is checking for the existence of a storage entry that
        // contains a username (any attacker could trivially fake this)
        // Note that this storage API may be inaccessible, which we completely ignore
        // here for simplicity
        let storage = web_sys::window().unwrap().local_storage().unwrap().unwrap();
        let auth_token = storage.get("username").unwrap(); // This is a `Result<Option<T>, E>`

        if let Some(username) = auth_token {
            self.username.set(username);
            self.state.set(LoginState::Yes);
        } else {
            self.username.set(String::new());
            self.state.set(LoginState::No)
        }
    }