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
2 changes: 1 addition & 1 deletion apps/web/app/api/ai/analyze-sender-pattern/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function process({
const gmail = await getGmailClientWithRefresh({
accessToken: account.access_token,
refreshToken: account.refresh_token,
expiresAt: account.expires_at,
expiresAt: account.expires_at?.getTime() || null,
emailAccountId,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/clean/gmail/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function performGmailAction({
const gmail = await getGmailClientWithRefresh({
accessToken: account.account.access_token,
refreshToken: account.account.refresh_token,
expiresAt: account.account.expires_at,
expiresAt: account.account.expires_at?.getTime() || null,
emailAccountId,
});

Expand Down
1 change: 0 additions & 1 deletion apps/web/app/api/google/contacts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const GET = withEmailAccount(async (request) => {
const client = getContactsClient({
accessToken: emailAccount?.account.access_token,
refreshToken: emailAccount?.account.refresh_token,
expiryDate: emailAccount?.account.expires_at,
});

const { searchParams } = new URL(request.url);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/google/watch/all/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async function watchAllEmails() {
const gmail = await getGmailClientWithRefresh({
accessToken: emailAccount.account.access_token,
refreshToken: emailAccount.account.refresh_token,
expiresAt: emailAccount.account.expires_at,
expiresAt: emailAccount.account.expires_at?.getTime() || null,
emailAccountId: emailAccount.id,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/google/webhook/process-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export async function processHistoryForUser(
const gmail = await getGmailClientWithRefresh({
accessToken: emailAccount.account?.access_token,
refreshToken: emailAccount.account?.refresh_token,
expiresAt: emailAccount.account?.expires_at,
expiresAt: emailAccount.account?.expires_at?.getTime() || null,
emailAccountId: emailAccount.id,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/outlook/watch/all/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async function watchAllEmails() {
const outlookClient = await getOutlookClientWithRefresh({
accessToken: emailAccount.account.access_token,
refreshToken: emailAccount.account.refresh_token,
expiresAt: emailAccount.account.expires_at,
expiresAt: emailAccount.account.expires_at?.getTime() || null,
emailAccountId: emailAccount.id,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/outlook/watch/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const GET = withAuth(async (request) => {
const outlookClient = await getOutlookClientWithRefresh({
accessToken: account.account.access_token,
refreshToken: account.account.refresh_token,
expiresAt: account.account.expires_at,
expiresAt: account.account.expires_at?.getTime() || null,
emailAccountId,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/outlook/webhook/process-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export async function processHistoryForUser({
const outlookClient = await getOutlookClientWithRefresh({
accessToken: emailAccount.account?.access_token,
refreshToken: emailAccount.account?.refresh_token,
expiresAt: emailAccount.account?.expires_at,
expiresAt: emailAccount.account?.expires_at?.getTime() || null,
emailAccountId: emailAccount.id,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function handleBatchInternal(request: Request) {
const gmail = await getGmailClientWithRefresh({
accessToken: account.access_token,
refreshToken: account.refresh_token,
expiresAt: account.expires_at,
expiresAt: account.expires_at?.getTime() || null,
emailAccountId,
});

Expand Down
14 changes: 7 additions & 7 deletions apps/web/utils/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function getGmailClientForEmail({
const gmail = getGmailClientWithRefresh({
accessToken: tokens.accessToken,
refreshToken: tokens.refreshToken || "",
expiresAt: tokens.expiresAt ?? null,
expiresAt: tokens.expiresAt,
emailAccountId,
});
return gmail;
Expand All @@ -36,7 +36,7 @@ export async function getGmailAndAccessTokenForEmail({
const gmail = await getGmailClientWithRefresh({
accessToken: tokens.accessToken,
refreshToken: tokens.refreshToken || "",
expiresAt: tokens.expiresAt ?? null,
expiresAt: tokens.expiresAt,
emailAccountId,
});
const accessToken = getAccessTokenFromClient(gmail);
Expand All @@ -59,7 +59,7 @@ export async function getGmailClientForEmailId({
const gmail = getGmailClientWithRefresh({
accessToken: account?.account.access_token,
refreshToken: account?.account.refresh_token || "",
expiresAt: account?.account.expires_at ?? null,
expiresAt: account?.account.expires_at?.getTime() ?? null,
emailAccountId,
});
return gmail;
Expand All @@ -74,7 +74,7 @@ export async function getOutlookClientForEmail({
const outlook = await getOutlookClientWithRefresh({
accessToken: tokens.accessToken,
refreshToken: tokens.refreshToken || "",
expiresAt: tokens.expiresAt ?? null,
expiresAt: tokens.expiresAt,
emailAccountId,
});
return outlook;
Expand All @@ -89,7 +89,7 @@ export async function getOutlookAndAccessTokenForEmail({
const outlook = await getOutlookClientWithRefresh({
accessToken: tokens.accessToken,
refreshToken: tokens.refreshToken || "",
expiresAt: tokens.expiresAt ?? null,
expiresAt: tokens.expiresAt,
emailAccountId,
});
const accessToken = getOutlookAccessToken(outlook);
Expand All @@ -112,7 +112,7 @@ export async function getOutlookClientForEmailId({
const outlook = await getOutlookClientWithRefresh({
accessToken: account?.account.access_token,
refreshToken: account?.account.refresh_token || "",
expiresAt: account?.account.expires_at ?? null,
expiresAt: account?.account.expires_at?.getTime() ?? null,
emailAccountId,
});
return outlook;
Expand All @@ -131,7 +131,7 @@ async function getTokens({ emailAccountId }: { emailAccountId: string }) {
return {
accessToken: emailAccount?.account.access_token,
refreshToken: emailAccount?.account.refresh_token,
expiresAt: emailAccount?.account.expires_at,
expiresAt: emailAccount?.account.expires_at?.getTime() ?? null,
};
}

Expand Down
4 changes: 2 additions & 2 deletions apps/web/utils/actions/categorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ export const categorizeSenderAction = actionClient
const userResult = await validateUserAndAiAccess({ emailAccountId });
const { emailAccount } = userResult;

if (!session.accessToken) throw new SafeError("No access token");
if (!session.session.token) throw new SafeError("No access token");

const result = await categorizeSender(
senderAddress,
emailAccount,
gmail,
session.accessToken,
session.session.token,
);

revalidatePath(prefixPath(emailAccountId, "/smart-categories"));
Expand Down
5 changes: 0 additions & 5 deletions apps/web/utils/actions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { z } from "zod";
import { after } from "next/server";
import { auth } from "@/utils/auth";
import prisma from "@/utils/prisma";
import { deleteUser } from "@/utils/user/delete";
import { extractGmailSignature } from "@/utils/gmail/signature";
Expand Down Expand Up @@ -81,10 +80,6 @@ export const resetAnalyticsAction = actionClient
export const deleteAccountAction = actionClientUser
.metadata({ name: "deleteAccount" })
.action(async ({ ctx: { userId } }) => {
try {
await auth.api.signOut();
} catch {}

await deleteUser({ userId });
});

Expand Down
2 changes: 1 addition & 1 deletion apps/web/utils/api-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function validateApiKeyAndGetGmailClient(request: NextRequest) {
const gmail = await getGmailClientWithRefresh({
accessToken: account.access_token,
refreshToken: account.refresh_token,
expiresAt: account.expires_at,
expiresAt: account.expires_at?.getTime() || null,
emailAccountId: account.id,
});

Expand Down
4 changes: 2 additions & 2 deletions apps/web/utils/gmail/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getAuth = ({
expiresAt,
...rest
}: AuthOptions) => {
const expiryDate = expiresAt ? expiresAt * 1000 : rest.expiryDate;
const expiryDate = expiresAt ? expiresAt : rest.expiryDate;

const googleAuth = new auth.OAuth2({
clientId: env.GOOGLE_CLIENT_ID,
Expand Down Expand Up @@ -63,7 +63,7 @@ export const getGmailClientWithRefresh = async ({
const auth = getAuth({ accessToken, refreshToken });
const g = gmail({ version: "v1", auth });

const expiryDate = expiresAt ? expiresAt * 1000 : null;
const expiryDate = expiresAt ? expiresAt : null;
if (expiryDate && expiryDate > Date.now()) return g;

// may throw `invalid_grant` error
Expand Down
2 changes: 1 addition & 1 deletion apps/web/utils/outlook/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const getOutlookClientWithRefresh = async ({
if (!refreshToken) throw new SafeError("No refresh token");

// Check if token needs refresh
const expiryDate = expiresAt ? expiresAt * 1000 : null;
const expiryDate = expiresAt ? expiresAt : null;
if (accessToken && expiryDate && expiryDate > Date.now()) {
return createOutlookClient(accessToken);
}
Expand Down
5 changes: 4 additions & 1 deletion apps/web/utils/user/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export async function getEmailAccountWithAiAndTokens({

return {
...emailAccount,
tokens: emailAccount.account,
tokens: {
...emailAccount.account,
expires_at: emailAccount.account.expires_at?.getTime() ?? null,
},
};
}

Expand Down
Loading