Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

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

78 changes: 78 additions & 0 deletions apps/api/openapi.gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,37 @@
}
}
},
"/nango/whoami": {
"get": {
"tags": [
"nango"
],
"operationId": "whoami",
"responses": {
"200": {
"description": "User info for all connections",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WhoAmIResponse"
}
}
}
},
"401": {
"description": "Unauthorized"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"bearer_auth": []
}
]
}
},
"/stt/listen": {
"get": {
"tags": [
Expand Down Expand Up @@ -3643,6 +3674,53 @@
"unknown"
]
},
"WhoAmIItem": {
"type": "object",
"required": [
"integration_id",
"connection_id"
],
"properties": {
"connection_id": {
"type": "string"
},
"display_name": {
"type": [
"string",
"null"
]
},
"email": {
"type": [
"string",
"null"
]
},
"error": {
"type": [
"string",
"null"
]
},
"integration_id": {
"type": "string"
}
}
},
"WhoAmIResponse": {
"type": "object",
"required": [
"accounts"
],
"properties": {
"accounts": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WhoAmIItem"
}
}
}
},
"WorkingLocationProperties": {
"type": "object",
"properties": {
Expand Down
39 changes: 39 additions & 0 deletions apps/web/src/hooks/use-whoami.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useQuery } from "@tanstack/react-query";
import { jwtDecode } from "jwt-decode";

import { whoami } from "@hypr/api-client";
import { createClient } from "@hypr/api-client/client";

import { env } from "@/env";
import { getAccessToken } from "@/functions/access-token";

export function useWhoAmI(enabled = true) {
const authQuery = useQuery({
queryKey: ["integration-status", "auth"],
queryFn: async () => {
const token = await getAccessToken();
return {
token,
userId: jwtDecode<{ sub: string }>(token).sub,
};
},
retry: false,
enabled,
});

return useQuery({
queryKey: ["whoami", authQuery.data?.userId],
enabled: enabled && !!authQuery.data?.userId,
queryFn: async () => {
const client = createClient({
baseUrl: env.VITE_API_URL,
headers: { Authorization: `Bearer ${authQuery.data?.token}` },
});
const { data, error } = await whoami({ client });
if (error) {
throw new Error("Failed to load account info");
}
return data?.accounts ?? [];
},
});
}
17 changes: 13 additions & 4 deletions apps/web/src/routes/_view/app/-account-integrations.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Link, useNavigate } from "@tanstack/react-router";
import { ChevronDown, PlusIcon } from "lucide-react";

import type { ConnectionItem } from "@hypr/api-client";
import type { ConnectionItem, WhoAmIItem } from "@hypr/api-client";
import {
DropdownMenu,
DropdownMenuContent,
Expand All @@ -11,6 +11,7 @@ import {

import { useBilling } from "@/hooks/use-billing";
import { useConnections } from "@/hooks/use-connections";
import { useWhoAmI } from "@/hooks/use-whoami";

const INTEGRATIONS = [
{ id: "google-calendar", name: "Google Calendar" },
Expand All @@ -20,11 +21,16 @@ export function IntegrationsSettingsCard() {
const navigate = useNavigate();
const { isPro } = useBilling();
const { data: connections, isLoading } = useConnections(isPro);
const { data: accounts } = useWhoAmI(isPro);

const getProviderConnections = (integrationId: string) => {
return connections?.filter((c) => c.integration_id === integrationId) ?? [];
};

const getAccountInfo = (connectionId: string) => {
return accounts?.find((a) => a.connection_id === connectionId);
};

return (
<div className="rounded-xs border border-neutral-100">
<div className="p-4">
Expand Down Expand Up @@ -86,6 +92,7 @@ export function IntegrationsSettingsCard() {
key={connection.connection_id}
connection={connection}
integrationId={integration.id}
account={getAccountInfo(connection.connection_id)}
/>
))}
</div>
Expand All @@ -100,12 +107,16 @@ export function IntegrationsSettingsCard() {
function ConnectionRow({
connection,
integrationId,
account,
}: {
connection: ConnectionItem;
integrationId: string;
account?: WhoAmIItem;
}) {
const navigate = useNavigate();
const isReconnectRequired = connection.status === "reconnect_required";
const displayLabel =
account?.email ?? account?.display_name ?? connection.connection_id;

return (
<div className="flex items-center justify-between rounded-md border border-neutral-100 px-3 py-2">
Expand All @@ -116,9 +127,7 @@ function ConnectionRow({
isReconnectRequired ? "bg-amber-500" : "bg-green-500",
].join(" ")}
/>
<span className="text-xs text-neutral-700">
{connection.connection_id}
</span>
<span className="text-xs text-neutral-700">{displayLabel}</span>
{isReconnectRequired && (
<span className="text-xs text-amber-600">Reconnect required</span>
)}
Expand Down
72 changes: 72 additions & 0 deletions crates/api-client/openapi.gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,47 @@
],
"type": "string"
},
"WhoAmIItem": {
"properties": {
"connection_id": {
"type": "string"
},
"display_name": {
"nullable": true,
"type": "string"
},
"email": {
"nullable": true,
"type": "string"
},
"error": {
"nullable": true,
"type": "string"
},
"integration_id": {
"type": "string"
}
},
"required": [
"integration_id",
"connection_id"
],
"type": "object"
},
"WhoAmIResponse": {
"properties": {
"accounts": {
"items": {
"$ref": "#/components/schemas/WhoAmIItem"
},
"type": "array"
}
},
"required": [
"accounts"
],
"type": "object"
},
"WorkingLocationProperties": {
"properties": {
"customLocation": {
Expand Down Expand Up @@ -2587,6 +2628,37 @@
]
}
},
"/nango/whoami": {
"get": {
"operationId": "whoami",
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/WhoAmIResponse"
}
}
},
"description": "User info for all connections"
},
"401": {
"description": "Unauthorized"
},
"500": {
"description": "Internal server error"
}
},
"security": [
{
"bearer_auth": []
}
],
"tags": [
"nango"
]
}
},
"/subscription/can-start-trial": {
"get": {
"operationId": "can_start_trial",
Expand Down
1 change: 1 addition & 0 deletions crates/api-nango/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ urlencoding = { workspace = true }
utoipa = { workspace = true }

axum = { workspace = true }
futures-util = { workspace = true }
reqwest = { workspace = true, features = ["json"] }
sentry = { workspace = true }
tokio = { workspace = true }
Expand Down
6 changes: 5 additions & 1 deletion crates/api-nango/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use utoipa::OpenApi;

use crate::routes::{
ConnectionItem, CreateSessionRequest, DeleteConnectionRequest, DeleteConnectionResponse,
ListConnectionsResponse, SessionMode, SessionResponse, WebhookResponse,
ListConnectionsResponse, SessionMode, SessionResponse, WebhookResponse, WhoAmIItem,
WhoAmIResponse,
};

#[derive(OpenApi)]
Expand All @@ -12,6 +13,7 @@ use crate::routes::{
crate::routes::disconnect::delete_connection,
crate::routes::status::list_connections,
crate::routes::webhook::nango_webhook,
crate::routes::whoami::whoami,
),
components(
schemas(
Expand All @@ -23,6 +25,8 @@ use crate::routes::{
ConnectionItem,
ListConnectionsResponse,
WebhookResponse,
WhoAmIItem,
WhoAmIResponse,
)
),
tags(
Expand Down
3 changes: 3 additions & 0 deletions crates/api-nango/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub(crate) mod connect;
pub(crate) mod disconnect;
pub(crate) mod status;
pub(crate) mod webhook;
pub(crate) mod whoami;

use axum::{
Router,
Expand All @@ -15,6 +16,7 @@ pub use connect::{CreateSessionRequest, SessionMode, SessionResponse};
pub use disconnect::{DeleteConnectionRequest, DeleteConnectionResponse};
pub use status::{ConnectionItem, ListConnectionsResponse};
pub use webhook::WebhookResponse;
pub use whoami::{WhoAmIItem, WhoAmIResponse};

pub fn router(config: NangoConfig) -> Router {
let state = AppState::new(config);
Expand All @@ -25,6 +27,7 @@ pub fn router(config: NangoConfig) -> Router {
"/connections",
get(status::list_connections).delete(disconnect::delete_connection),
)
.route("/whoami", get(whoami::whoami))
.with_state(state)
}

Expand Down
Loading
Loading