use leptos::prelude::*;
use leptos_meta::{MetaTags, Stylesheet, Title, provide_meta_context};
use leptos_oidc::{Auth, AuthParameters, AuthSignal, Challenge, LoginLink};
use leptos_router::{
StaticSegment,
components::{Route, Router, Routes},
};
use url::Url;
use crate::pages::{AboutPage, HomePage, ProviderEntry};
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
}
}
#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();
// Authentication setup
let parameters = AuthParameters {
issuer: "https://cognito-idp.us-east-1.amazonaws.com/us-east-1_Lfjuy5zaM".into(),
client_id: "10jr2h3vtpu9n7gj46pvg5qo2q".into(),
redirect_uri: Url::parse("http://localhost:3000").unwrap().to_string(),
post_logout_redirect_uri: Url::parse("http://localhost:3000").unwrap().to_string(),
scope: Some("openid%20profile%20email".into()),
audience: None,
challenge: Challenge::None,
};
let auth = Auth::signal();
provide_context(auth); // allows use of this signal in lower areas of the tree without
// explicitly passing it through the html tree
let _ = Auth::init(parameters);
view! {
// injects a stylesheet into the document
// id=leptos means cargo-leptos will hot-reload this stylesheet
// "Authentication is loading"
//
// sets the document title
// content for this welcome page
// TODO Create a 404 page
}
}
#[component]
pub fn Unauthenticated() -> impl IntoView {
view! {
"Error 401: Unauthorized"
"Sign in"
}
}
#[component]
pub fn AuthErrorView() -> impl IntoView {
let auth = use_context::().expect("AuthError: RwSignal was not found");
let error_message = move || auth.get().error().map(|error| format!("{error:?}"));
view! {
"An authentication error occurred."
{error_message}
}
}