i get a principal id in the localhost frontend app in which i ahve implemented auth login using ic-auth-client different from when i login in this https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=7amc6-qqaaa-aaaam-acntq-cai
the login method in my frontend is:
pub async fn login(&mut self) → Result<(), String> {
let mut dfx_network = dotenv!(“BACKEND”).to_string();
if dfx_network.is_empty() {
dfx_network = env::var(“BACKEND”).expect(“BACKEND is must be set”);
}
let identity_provider: Option<Url> = match dfx_network.as_str() {
"LOCAL" => Some({
let port = 4943;
let canister_id = BACKEND_ID;
Url::new(&format!("http://{}.localhost:{}", canister_id, port)).unwrap()
}),
"LIVE" => Some(Url::new("https://identity.ic0.app/#authorize").unwrap()),
_ => panic!("Unknown dfx network: {}", dfx_network),
};
let mut builder = AuthClientLoginOptions::builder()
.max_time_to_live(7 * 24 * 60 * 60 * 1_000_000_000) // 7 days in nanoseconds
.on_success(|_| {
// Handle successful login
info!("Login successful");
})
.on_error(|_error| {
// Handle login error
// info!(&format!("Login failed: {:?}", error));
});
// Only set the identity_provider if it's Some
if let Some(provider) = identity_provider {
builder = builder.identity_provider(provider);
}
let options = builder.build();
// Use await here to wait for the login process to complete
self.auth_client.login_with_options(options);
// Verify authentication after login
if self.auth_client.is_authenticated() {
// window().unwrap().location().reload().unwrap();
Ok(())
} else {
Err("Authentication failed".to_string())
}
}