Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: auth_redirect to principle ID #628

Merged
merged 32 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b67af1b
Make send_event_ssr a server function
vishnu-shankar-yral Jan 15, 2025
7cdea34
Replace send_event with send_event_ssr
vishnu-shankar-yral Jan 15, 2025
1798526
Replace send_event_warehouse with send_event_warehouse_ssr
vishnu-shankar-yral Jan 15, 2025
2c31f12
Fix serialization issues with events
vishnu-shankar-yral Jan 17, 2025
f4c54c4
Fix google analytics event schema
vishnu-shankar-yral Jan 20, 2025
64c5d56
Change host condition for testing
vishnu-shankar-yral Jan 20, 2025
f31282c
Menu Auth Fix (#614)
joel-medicala-yral Jan 21, 2025
f4b7763
Merge pull request #606 from yral-dapp/96-unified-dau-number
vishnu-shankar-yral Jan 21, 2025
6304b8e
Airdrop layout (#607)
joel-medicala-yral Jan 22, 2025
00241ee
Airdrop button fix (#622)
joel-medicala-yral Jan 22, 2025
76424dd
BUG: auth_redirect to principle ID
harsh-mahajan-yral Jan 23, 2025
ca9157d
UPGRADE: github action upload-artifact
harsh-mahajan-yral Jan 23, 2025
9f0da8c
Add page visit event
vishnu-shankar-yral Jan 24, 2025
cb1fdb9
Fix lint issues
vishnu-shankar-yral Jan 24, 2025
806909f
Add reactivity to page visit event
vishnu-shankar-yral Jan 24, 2025
5d46082
Fix lint errors
vishnu-shankar-yral Jan 24, 2025
0ba727d
Merge pull request #630 from yral-dapp/96-unified-dau-number
vishnu-shankar-yral Jan 24, 2025
f2245b3
Merge pull request #629 from yral-dapp/artifact_upgrade
rupansh-sekar-yral Jan 24, 2025
272252a
update to v4 migration
harsh-mahajan-yral Jan 25, 2025
fdc0b4d
platform conditional nix changes
harsh-mahajan-yral Jan 25, 2025
9630e54
Merge pull request #632 from yral-dapp/artifact_upgrade
rupansh-sekar-yral Jan 25, 2025
0a293f0
Merge branch 'main' into nix_changes
harsh-mahajan-yral Jan 26, 2025
184bcad
Merge branch 'main' into auth_redirect
harsh-mahajan-yral Jan 26, 2025
49d78d6
Merge pull request #633 from yral-dapp/nix_changes
harsh-mahajan-yral Jan 29, 2025
f6614e0
feat: expose endpoint for google auth url (#590)
ravi-sawlani-yral Jan 29, 2025
c5c9e8a
Profile route auth fix (#626)
joel-medicala-yral Jan 29, 2025
f857309
fix: google external client redirect parameters (#635)
ravi-sawlani-yral Jan 29, 2025
e650e9d
Merge branch 'main' into auth_redirect
ravi-sawlani-yral Jan 29, 2025
35c719c
feat: add cors for preview link urls (#641)
ravi-sawlani-yral Jan 30, 2025
76f9ac2
Merge branch 'main' into auth_redirect
harsh-mahajan-yral Jan 30, 2025
8893fee
merge conflicts
harsh-mahajan-yral Jan 30, 2025
344924f
lint
harsh-mahajan-yral Jan 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
LEPTOS_HASH_FILES: true
- run: touch .empty
- name: Archive production artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ inputs.publish-artifact }}
with:
name: build-musl
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Download build
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: build-musl
- run: chmod +x target/x86_64-unknown-linux-musl/release/hot-or-not-web-leptos-ssr
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Download build
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: build-musl
- run: chmod +x target/x86_64-unknown-linux-musl/release/hot-or-not-web-leptos-ssr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Download build
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: build-musl
- run: chmod +x target/x86_64-unknown-linux-musl/release/hot-or-not-web-leptos-ssr
Expand Down
23 changes: 12 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ pkgs.mkShell {
pkgs.darwin.libiconv
] else []);
shellHook = ''
export LLVM_PATH=/opt/homebrew/opt/llvm/
if [ -d "/opt/homebrew/opt/llvm" ]; then
export LLVM_PATH="/opt/homebrew/opt/llvm"
else
export LLVM_PATH="$(which llvm)"
fi
export RUSTC_WRAPPER=""
export CC_wasm32_unknown_unknown=$LLVM_PATH/bin/clang
export CXX_wasm32_unknown_unknown=$LLVM_PATH/bin/clang++
Expand Down
4 changes: 3 additions & 1 deletion ssr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tokio = { version = "1", optional = true, features = [
"time",
] }
tower = { version = "0.4", optional = true }
tower-http = { version = "0.5", features = ["fs"], optional = true }
tower-http = { version = "0.5", features = ["fs", "cors"], optional = true }
wasm-bindgen = "=0.2.93"
thiserror = "1.0"
tracing = { version = "0.1.37", optional = true }
Expand Down Expand Up @@ -117,6 +117,7 @@ ic-certification = "2.6.0"
ciborium = "0.2.2"
yral-metadata-client = { git = "https://github.com/yral-dapp/yral-metadata", rev = "56e3f1f1f5f452673bee17739520c800c1264295", optional = true }
yral-metadata-types = { git = "https://github.com/yral-dapp/yral-metadata", rev = "56e3f1f1f5f452673bee17739520c800c1264295", optional = true }
regex = { version = "1.11.1", optional = true }

[build-dependencies]
tonic-build = { version = "0.12.0", default-features = false, features = [
Expand Down Expand Up @@ -164,6 +165,7 @@ ssr = [
"tonic/transport",
"tonic-build/transport",
"speedate",
"dep:regex",
]
# Fetch mock referral history instead of history via canister
mock-referral-history = ["dep:rand_chacha", "k256/arithmetic"]
Expand Down
2 changes: 1 addition & 1 deletion ssr/contracts
1 change: 0 additions & 1 deletion ssr/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ pub fn App() -> impl IntoView {
<Route path="/token/transfer/:token_root" view=TokenTransfer/>
<Route path="/board" view=ICPumpLanding/>
<Route path="/icpump-ai" view=ICPumpAi/>
// <Route path="/test" view=TestIndex/>
</Route>
</Routes>

Expand Down
14 changes: 12 additions & 2 deletions ssr/src/component/auth_providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use candid::Principal;
use codee::string::FromToStringCodec;
use ic_agent::Identity;
use leptos::*;
use leptos_router::{use_location, use_navigate, NavigateOptions};
use leptos_use::storage::use_local_storage;
use yral_types::delegated_identity::DelegatedIdentityWire;

Expand Down Expand Up @@ -108,6 +109,7 @@ fn LoginProvButton<Cb: Fn(ev::MouseEvent) + 'static>(

#[component]
pub fn LoginProviders(show_modal: RwSignal<bool>, lock_closing: RwSignal<bool>) -> impl IntoView {
let location = use_location();
let (_, write_account_connected, _) =
use_local_storage::<bool, FromToStringCodec>(ACCOUNT_CONNECTED_STORE);
let auth = auth_state();
Expand All @@ -129,8 +131,16 @@ pub fn LoginProviders(show_modal: RwSignal<bool>, lock_closing: RwSignal<bool>)
// This is some redundant work, but saves us 100+ lines of resource handling
let canisters = Canisters::authenticate_with_network(identity, referrer).await?;

if let Err(e) = handle_user_login(canisters.clone(), referrer).await {
log::warn!("failed to handle user login, err {e}. skipping");
if (handle_user_login(canisters.clone(), referrer).await).is_ok() {
let user_principal = canisters.identity().sender().unwrap();

if location.pathname.get().starts_with("/profile") {
let navigate = use_navigate();
navigate(
&format!("/profile/{}", user_principal),
NavigateOptions::default(),
);
}
}

LoginSuccessful.send_event(canisters);
Expand Down
10 changes: 9 additions & 1 deletion ssr/src/component/base_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use leptos_use::use_cookie;

use crate::auth::delegate_identity;
use crate::consts::{ACCOUNT_CONNECTED_STORE, USER_CANISTER_ID_STORE, USER_PRINCIPAL_STORE};
use crate::utils::event_streaming::events::PageVisit;
use crate::utils::ParentResource;
use crate::{
auth::{
Expand Down Expand Up @@ -109,6 +110,8 @@ fn CtxProvider(temp_identity: Option<JwkEcKey>, children: ChildrenFn) -> impl In
));
provide_context(canisters_res.clone());

let location = leptos_router::use_location();

view! {
{children}
<Suspense>
Expand All @@ -124,7 +127,12 @@ fn CtxProvider(temp_identity: Option<JwkEcKey>, children: ChildrenFn) -> impl In
set_user_canister_id(Some(user_canister));
set_user_principal(Some(user_principal));
});
canisters_store.set(Some(cans));
canisters_store.set(Some(cans.clone()));
create_effect(move |_| {
let pathname = location.pathname.get();
let cans = cans.clone();
PageVisit.send_event(cans, pathname);
});
})
}}

Expand Down
23 changes: 15 additions & 8 deletions ssr/src/component/content_upload.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
use super::spinner::Spinner;
use crate::{
auth::delegate_short_lived_identity, page::menu::AuthorizedUserToSeedContent,
state::content_seed_client::ContentSeedClient,
auth::delegate_short_lived_identity,
page::menu::AuthorizedUserToSeedContent,
state::{canisters::authenticated_canisters, content_seed_client::ContentSeedClient},
};
use candid::Principal;
use leptos::*;
use yral_canisters_common::Canisters;

#[component]
fn YoutubeUploadInner(canisters: Canisters<true>, #[prop(optional)] url: String) -> impl IntoView {
fn YoutubeUploadInner(#[prop(optional)] url: String) -> impl IntoView {
let url_value = RwSignal::new(url);
let create_short_lived_delegated_identity = |canisters: &Canisters<true>| {
let id = canisters.identity();
delegate_short_lived_identity(id)
};

let authenticated_canisters = authenticated_canisters();
let on_submit = create_action(move |_| {
let canisters_copy = canisters.clone();
let authenticated_canisters = authenticated_canisters.clone();
async move {
let canisters_copy = Canisters::from_wire(
authenticated_canisters.wait_untracked().await.unwrap(),
expect_context(),
)
.unwrap();

let delegated_identity = create_short_lived_delegated_identity(&canisters_copy);
let content_seed_client: ContentSeedClient = expect_context();
let res = content_seed_client
Expand Down Expand Up @@ -70,9 +79,7 @@ fn YoutubeUploadInner(canisters: Canisters<true>, #[prop(optional)] url: String)
}

#[component]
pub fn YoutubeUpload(canisters: Canisters<true>, #[prop(optional)] url: String) -> impl IntoView {
let user_principal = canisters.user_principal();
let cans_s = store_value(canisters);
pub fn YoutubeUpload(#[prop(optional)] url: String, user_principal: Principal) -> impl IntoView {
let url_s = store_value(url);

let authorized_ctx: AuthorizedUserToSeedContent = expect_context();
Expand All @@ -86,7 +93,7 @@ pub fn YoutubeUpload(canisters: Canisters<true>, #[prop(optional)] url: String)
view! {
<Show when=loaded fallback=Spinner>
<Show when=move || authorized().map(|(a, _)| a).unwrap_or_default()>
<YoutubeUploadInner canisters=cans_s.get_value() url=url_s.get_value() />
<YoutubeUploadInner url=url_s.get_value() />
</Show>
</Show>
}
Expand Down
26 changes: 24 additions & 2 deletions ssr/src/component/spinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,30 @@ icon_gen!(
"###
);
#[component]
pub fn SpinnerCircle() -> impl IntoView {
pub fn SpinnerCircle(#[prop(optional, default = "")] class: &'static str) -> impl IntoView {
view! {
<Icon icon=SpinnerCircleIcon class="animate-spin w-full h-full"/>
<Icon icon=SpinnerCircleIcon class=format!("animate-spin w-full h-full {}", class)/>
}
}
#[component]
pub fn SpinnerCircleStyled(#[prop(optional, default = "")] class: &'static str) -> impl IntoView {
view! {
<Icon icon=SpinnerCircleStyledIcon class=format!("animate-spin w-full h-full {}", class)/>
}
}
icon_gen!(
SpinnerCircleStyledIcon,
view_box = "0 0 49 48",
r###"
<path opacity="0.38" d="M48.5 24C48.5 37.2548 37.7548 48 24.5 48C11.2452 48 0.5 37.2548 0.5 24C0.5 10.7452 11.2452 0 24.5 0C37.7548 0 48.5 10.7452 48.5 24ZM7.98361 24C7.98361 33.1218 15.3782 40.5164 24.5 40.5164C33.6218 40.5164 41.0164 33.1218 41.0164 24C41.0164 14.8782 33.6218 7.48361 24.5 7.48361C15.3782 7.48361 7.98361 14.8782 7.98361 24Z" fill="#EC55A7"/>
<path d="M44.7582 24C46.8247 24 48.5298 22.3148 48.2089 20.2733C47.9151 18.4041 47.4006 16.5718 46.6731 14.8156C45.467 11.9038 43.6992 9.25804 41.4706 7.02944C39.242 4.80083 36.5962 3.033 33.6844 1.82689C31.9282 1.09944 30.0959 0.584918 28.2267 0.291103C26.1852 -0.0297888 24.5 1.67526 24.5 3.7418C24.5 5.80834 26.1962 7.44147 28.2099 7.90566C29.0997 8.11075 29.973 8.38977 30.8205 8.74084C32.8244 9.57087 34.6452 10.7875 36.1789 12.3211C37.7125 13.8548 38.9291 15.6756 39.7592 17.6794C40.1102 18.527 40.3892 19.4003 40.5943 20.2901C41.0585 22.3038 42.6917 24 44.7582 24Z" fill="url(#paint0_linear_134_12800)"/>
<defs>
<linearGradient id="paint0_linear_134_12800" x1="45.8334" y1="6.33333" x2="17.1668" y2="42.6668" gradientUnits="userSpaceOnUse">
<stop stop-color="#FF78C1"/>
<stop offset="0.509385" stop-color="#E2017B"/>
<stop offset="1" stop-color="#5F0938"/>
</linearGradient>
</defs>

"###
);
14 changes: 13 additions & 1 deletion ssr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ use axum::{
response::{IntoResponse, Response},
};
use axum::{routing::get, Router};
use hot_or_not_web_leptos_ssr::fallback::file_and_error_handler;
use hot_or_not_web_leptos_ssr::{app::App, init::AppStateBuilder, state::server::AppState};
use hot_or_not_web_leptos_ssr::{
fallback::file_and_error_handler, utils::host::is_host_a_preview_link,
};
use leptos::{get_configuration, logging::log, provide_context};
use leptos_axum::handle_server_fns_with_context;
use leptos_axum::{generate_route_list, LeptosRoutes};
use tower_http::cors::{AllowOrigin, CorsLayer};

pub async fn server_fn_handler(
State(app_state): State<AppState>,
Expand Down Expand Up @@ -139,6 +142,15 @@ async fn main() {
"/api/*fn_name",
get(server_fn_handler).post(server_fn_handler),
)
.layer(
CorsLayer::new().allow_origin(AllowOrigin::predicate(|origin, _| {
if let Ok(host) = origin.to_str() {
is_host_a_preview_link(host) || host == "yral.com"
} else {
false
}
})),
)
.leptos_routes_with_handler(routes, get(leptos_routes_handler))
.fallback(file_and_error_handler)
.with_state(res.app_state);
Expand Down
Loading
Loading