Skip to content

Commit

Permalink
Disable fetching orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunkomath committed Jan 11, 2025
1 parent 6b1b05d commit d1c94ae
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 176 deletions.
70 changes: 36 additions & 34 deletions app/(dashboard)/[tenant]/today/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,43 @@ export default async function Today() {
</p>
</PageSection>

<PageSection>
{overDue.length ? (
<>
<p className="flex items-center p-4 text-xl font-medium text-red-600">
<AlertTriangleIcon className="w-6 h-6 inline-block mr-1" />
Overdue
</p>
{overDue.map((task) => (
<TaskItem
key={task.id}
task={task}
projectId={+task.taskList.projectId}
compact
/>
))}
</>
) : null}
{overDue.length || dueToday.length ? (
<PageSection>
{overDue.length ? (
<>
<p className="flex items-center p-4 text-xl font-medium text-red-600">
<AlertTriangleIcon className="w-6 h-6 inline-block mr-1" />
Overdue
</p>
{overDue.map((task) => (
<TaskItem
key={task.id}
task={task}
projectId={+task.taskList.projectId}
compact
/>
))}
</>
) : null}

{dueToday.length ? (
<>
<p className="flex items-center p-4 text-xl font-medium text-orange-600">
<InfoIcon className="w-6 h-6 inline-block mr-1" />
Due Today
</p>
{dueToday.map((task) => (
<TaskItem
key={task.id}
task={task}
projectId={+task.taskList.projectId}
compact
/>
))}
</>
) : null}
</PageSection>
{dueToday.length ? (
<>
<p className="flex items-center p-4 text-xl font-medium text-orange-600">
<InfoIcon className="w-6 h-6 inline-block mr-1" />
Due Today
</p>
{dueToday.map((task) => (
<TaskItem
key={task.id}
task={task}
projectId={+task.taskList.projectId}
compact
/>
))}
</>
) : null}
</PageSection>
) : null}
</>
);
}
59 changes: 31 additions & 28 deletions docker/local/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
services:
logto_app:
depends_on:
logto_postgres:
condition: service_healthy
image: svhd/logto:${TAG-latest}
entrypoint: ["sh", "-c", "npm run cli db seed -- --swe && npm start"]
ports:
- 3001:3001
- 3002:3002
environment:
- TRUST_PROXY_HEADER=1
- DB_URL=postgres://postgres:p0stgr3s@logto_postgres:5432/logto
# Mandatory for GitPod to map host env to the container, thus GitPod can dynamically configure the public URL of Logto;
# Or, you can leverage it for local testing.
- ENDPOINT
- ADMIN_ENDPOINT
logto_postgres:
image: postgres:17-alpine
user: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: p0stgr3s
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
# Use the following services to run Logto in a local environment.
# logto_app:
# depends_on:
# logto_postgres:
# condition: service_healthy
# image: svhd/logto:${TAG-latest}
# entrypoint: ["sh", "-c", "npm run cli db seed -- --swe && npm start"]
# ports:
# - 3001:3001
# - 3002:3002
# environment:
# - TRUST_PROXY_HEADER=1
# - DB_URL=postgres://postgres:p0stgr3s@logto_postgres:5432/logto
# # Mandatory for GitPod to map host env to the container, thus GitPod can dynamically configure the public URL of Logto;
# # Or, you can leverage it for local testing.
# - ENDPOINT
# - ADMIN_ENDPOINT
# logto_postgres:
# image: postgres:17-alpine
# user: postgres
# environment:
# POSTGRES_USER: postgres
# POSTGRES_PASSWORD: p0stgr3s
# healthcheck:
# test: ["CMD-SHELL", "pg_isready"]
# interval: 10s
# timeout: 5s
# retries: 5

# Use the following services to run MinIO (S3 compatible storage) in a local environment.
minio:
image: quay.io/minio/minio
ports:
Expand All @@ -36,4 +39,4 @@ services:
MINIO_ROOT_PASSWORD: ROOTPASSWORD
volumes:
- ./blob-data:/data
command: server /data --console-address ":9001"
command: server /data --console-address ":9001"
230 changes: 116 additions & 114 deletions lib/ops/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,135 +10,137 @@ const tenantId = "default";
*/

export interface User {
id: string;
username: string;
primaryEmail: string | null;
name: string | null;
avatar: string | null;
customData: {
timezone: string;
};
lastSignInAt: number;
createdAt: number;
updatedAt: number;
isSuspended: boolean;
hasPassword: boolean;
id: string;
username: string;
primaryEmail: string | null;
name: string | null;
avatar: string | null;
customData: {
timezone: string;
};
lastSignInAt: number;
createdAt: number;
updatedAt: number;
isSuspended: boolean;
hasPassword: boolean;
}

export interface Organization {
tenantId: string;
id: string;
name: string;
description: string;
customData: Record<string, string | number | boolean>;
isMfaRequired: boolean;
branding: {
logoUrl: string;
darkLogoUrl: string;
favicon: string;
darkFavicon: string;
};
createdAt: number;
organizationRoles: {
id: string;
name: string;
}[];
tenantId: string;
id: string;
name: string;
description: string;
customData: Record<string, string | number | boolean>;
isMfaRequired: boolean;
branding: {
logoUrl: string;
darkLogoUrl: string;
favicon: string;
darkFavicon: string;
};
createdAt: number;
organizationRoles: {
id: string;
name: string;
}[];
}

export const fetchAccessToken = async () => {
const { endpoint } = logtoConfig;
return await fetch(`${endpoint}oidc/token`, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${Buffer.from(
`${applicationId}:${applicationSecret}`,
).toString("base64")}`,
},
body: new URLSearchParams({
grant_type: "client_credentials",
resource: `https://${tenantId}.logto.app/api`,
scope: "all",
}).toString(),
});
const { endpoint } = logtoConfig;
return await fetch(`${endpoint}oidc/token`, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Authorization: `Basic ${Buffer.from(
`${applicationId}:${applicationSecret}`,
).toString("base64")}`,
},
body: new URLSearchParams({
grant_type: "client_credentials",
resource: `https://${tenantId}.logto.app/api`,
scope: "all",
}).toString(),
});
};

export const getUser = async (userId: string): Promise<User> => {
const { access_token } = await fetchAccessToken().then((res) => res.json());
if (!access_token) {
throw new Error("Access token not found");
}

const { endpoint } = logtoConfig;
const response = await fetch(`${endpoint}api/users/${userId}`, {
method: "GET",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
});

if (!response.ok) {
console.error("Failed to fetch user", response.status);
throw new Error("Failed to fetch user");
}

return await response.json();
const { access_token } = await fetchAccessToken().then((res) => res.json());
if (!access_token) {
throw new Error("Access token not found");
}

const { endpoint } = logtoConfig;
const response = await fetch(`${endpoint}api/users/${userId}`, {
method: "GET",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
});

if (!response.ok) {
console.error("Failed to fetch user", response.status);
throw new Error("Failed to fetch user");
}

return await response.json();
};

export const updateUser = async (
userId: string,
data: {
name?: string;
primaryEmail?: string;
customData?: Record<string, unknown>;
},
userId: string,
data: {
name?: string;
primaryEmail?: string;
customData?: Record<string, unknown>;
},
) => {
const { access_token } = await fetchAccessToken().then((res) => res.json());
if (!access_token) {
throw new Error("Access token not found");
}

const { endpoint } = logtoConfig;
const response = await fetch(`${endpoint}api/users/${userId}`, {
method: "PATCH",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});

if (!response.ok) {
console.error("Failed to update user", response.status);
throw new Error("Failed to update user");
}

return await response.json();
const { access_token } = await fetchAccessToken().then((res) => res.json());
if (!access_token) {
throw new Error("Access token not found");
}

const { endpoint } = logtoConfig;
const response = await fetch(`${endpoint}api/users/${userId}`, {
method: "PATCH",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});

if (!response.ok) {
console.error("Failed to update user", response.status);
throw new Error("Failed to update user");
}

return await response.json();
};

export const getOrganizationsForUser = async (
userId: string,
userId: string,
): Promise<Organization[]> => {
const { access_token } = await fetchAccessToken().then((res) => res.json());
if (!access_token) {
throw new Error("Access token not found");
}

const { endpoint } = logtoConfig;
const response = await fetch(`${endpoint}api/users/${userId}/organizations`, {
method: "GET",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
});

if (!response.ok) {
console.error("Failed to fetch organizations", response.status);
throw new Error("Failed to fetch organizations");
}
const organizations = await response.json();

return organizations;
// is this slowing the app?
return [];
const { access_token } = await fetchAccessToken().then((res) => res.json());
if (!access_token) {
throw new Error("Access token not found");
}

const { endpoint } = logtoConfig;
const response = await fetch(`${endpoint}api/users/${userId}/organizations`, {
method: "GET",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
});

if (!response.ok) {
console.error("Failed to fetch organizations", response.status);
throw new Error("Failed to fetch organizations");
}
const organizations = await response.json();

return organizations;
};

0 comments on commit d1c94ae

Please sign in to comment.