mirror of
https://github.com/Mail-0/Zero.git
synced 2026-07-01 08:16:28 +00:00
Merge pull request #963 from Mail-0/dakdevs/staging/broken-connections-fix
Fix redirection for Invalid Connections
This commit is contained in:
@@ -39,6 +39,7 @@ export const makeQueryClient = (session: Session | null) =>
|
||||
signOut({
|
||||
fetchOptions: {
|
||||
onSuccess: () => {
|
||||
if (window.location.href.includes('/login')) return;
|
||||
window.location.href = '/login?error=required_scopes_missing';
|
||||
},
|
||||
},
|
||||
@@ -91,8 +92,13 @@ export const trpcClient = createTRPCClient<AppRouter>({
|
||||
methodOverride: 'POST',
|
||||
fetch: (url, options) =>
|
||||
fetch(url, { ...options, credentials: 'include' }).then((res) => {
|
||||
const currentPath = new URL(window.location.href).pathname;
|
||||
const redirectPath = res.headers.get('X-Zero-Redirect');
|
||||
if (redirectPath) window.location.href = redirectPath;
|
||||
|
||||
if (!!redirectPath && redirectPath !== currentPath) {
|
||||
window.location.href = redirectPath;
|
||||
}
|
||||
|
||||
return res;
|
||||
}),
|
||||
}),
|
||||
|
||||
@@ -13,10 +13,6 @@ export const getActiveConnection = async (c: HonoContext) => {
|
||||
if (!activeConnection)
|
||||
throw new Error(`Active connection not found for user ${session.user.id}`);
|
||||
|
||||
if (!activeConnection.refreshToken || !activeConnection.accessToken)
|
||||
throw new Error(
|
||||
'Active Connection is not properly authorized, please reconnect the connection',
|
||||
);
|
||||
return activeConnection;
|
||||
}
|
||||
|
||||
@@ -29,24 +25,20 @@ export const getActiveConnection = async (c: HonoContext) => {
|
||||
|
||||
if (!activeConnection) throw new Error('Active connection not found');
|
||||
|
||||
if (!activeConnection.refreshToken || !activeConnection.accessToken)
|
||||
throw new Error(
|
||||
'Active Connection is not properly authorized, please reconnect the connection',
|
||||
);
|
||||
return activeConnection;
|
||||
};
|
||||
|
||||
export const connectionToDriver = (
|
||||
activeConnection: typeof connection.$inferSelect,
|
||||
c: HonoContext,
|
||||
) => {
|
||||
const driver = createDriver(activeConnection.providerId, {
|
||||
export const connectionToDriver = (activeConnection: typeof connection.$inferSelect) => {
|
||||
if (!activeConnection.accessToken || !activeConnection.refreshToken) {
|
||||
throw new Error('Invalid connection');
|
||||
}
|
||||
|
||||
return createDriver(activeConnection.providerId, {
|
||||
auth: {
|
||||
accessToken: activeConnection.accessToken,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
refreshToken: activeConnection.refreshToken!,
|
||||
|
||||
refreshToken: activeConnection.refreshToken,
|
||||
email: activeConnection.email,
|
||||
},
|
||||
});
|
||||
return driver;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user