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

fix: user has to login every time chrome sidepanel is opened #5544

Merged
merged 37 commits into from
May 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2451b44
remove cache dir
AdityaPimpalkar May 22, 2024
074111b
change host permissions to only accept http connection
AdityaPimpalkar May 22, 2024
7a0ba5c
remove oauth code and add cookies onChanged listner
AdityaPimpalkar May 22, 2024
6951aea
refacto: seperate url inputs from sidepanel
AdityaPimpalkar May 22, 2024
287e77d
move input urls to new settings page
AdityaPimpalkar May 22, 2024
ebaec87
add local storage listeners to change state
AdityaPimpalkar May 22, 2024
9a5c743
define inital state for auth tokens
AdityaPimpalkar May 22, 2024
b96e66a
add comment for changing host permission
AdityaPimpalkar May 22, 2024
b608480
Merge branch 'remove-oauth' into sidepanel-multi-login-fix
AdityaPimpalkar May 22, 2024
46053be
WindowEventEffect
AdityaPimpalkar May 23, 2024
acaa2ef
update sidepanelUrl
AdityaPimpalkar May 23, 2024
92ca1b8
window listners on sidepanel
AdityaPimpalkar May 23, 2024
e9c1c3e
lint fix
AdityaPimpalkar May 23, 2024
c374efd
navigation fix
AdityaPimpalkar May 23, 2024
7911d4c
state cleanup
AdityaPimpalkar May 23, 2024
3cc6bb0
lint fix
AdityaPimpalkar May 23, 2024
31eda67
add chromeExtensionId to client config
AdityaPimpalkar May 23, 2024
979fe16
add chromeExtensionId state to frontend
AdityaPimpalkar May 23, 2024
67255e9
add isDefined checks
AdityaPimpalkar May 23, 2024
34a1b1f
Merge branch 'main' into sidepanel-multi-login-fix
AdityaPimpalkar May 24, 2024
b74d372
remove renewToken mutation
AdityaPimpalkar May 27, 2024
0da579d
window event provider
AdityaPimpalkar May 27, 2024
00df4a8
add accessToken expiry condition on sidepanel
AdityaPimpalkar May 27, 2024
fe014b8
lint fix
AdityaPimpalkar May 27, 2024
1a986c0
button mount fix
AdityaPimpalkar May 27, 2024
02984da
remove dependency
AdityaPimpalkar May 27, 2024
436e2e5
lint fix
AdityaPimpalkar May 27, 2024
b544978
build fix on project.json
AdityaPimpalkar May 28, 2024
75eebb3
add settings button
AdityaPimpalkar May 28, 2024
9df6169
sidepanel internal navigation fix
AdityaPimpalkar May 28, 2024
3b342c7
split window event to provider and effect
AdityaPimpalkar May 28, 2024
41cbf1f
add sidepanel navigation
AdityaPimpalkar May 28, 2024
b65e195
read cookies from clientUrl upon cookie change
AdityaPimpalkar May 28, 2024
8a840f4
lint fix
AdityaPimpalkar May 28, 2024
5687625
Merge branch 'main' into sidepanel-multi-login-fix
AdityaPimpalkar May 28, 2024
e9a7815
yarn lock
AdityaPimpalkar May 28, 2024
0e1ba39
rename WindowEvent to ChromeExtensionSidecar
AdityaPimpalkar May 30, 2024
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
Prev Previous commit
Next Next commit
remove renewToken mutation
  • Loading branch information
AdityaPimpalkar committed May 27, 2024
commit b74d37287fd46e0dbcbb7fb7c1521e8dabf859d9
48 changes: 6 additions & 42 deletions packages/twenty-chrome-extension/src/utils/apolloClient.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import {
ApolloClient,
from,
fromPromise,
HttpLink,
InMemoryCache,
} from '@apollo/client';
import { setContext } from '@apollo/client/link/context';
import { onError } from '@apollo/client/link/error';

import { renewToken } from '~/db/token.db';
import { Tokens } from '~/db/types/auth.types';
import { isDefined } from '~/utils/isDefined';

const clearStore = () => {
export const clearStore = () => {
chrome.storage.local.remove([
'loginToken',
'accessToken',
Expand All @@ -22,19 +19,6 @@ const clearStore = () => {
chrome.storage.local.set({ isAuthenticated: false });
};

const setStore = (tokens: Tokens) => {
if (isDefined(tokens.loginToken)) {
chrome.storage.local.set({
loginToken: tokens.loginToken,
});
}
chrome.storage.local.set({
isAuthenticated: true,
accessToken: tokens.accessToken,
refreshToken: tokens.refreshToken,
});
};

export const getServerUrl = async () => {
const store = await chrome.storage.local.get();
const serverUrl = `${
Expand All @@ -52,8 +36,6 @@ const getAuthToken = async () => {
};

const getApolloClient = async () => {
const store = await chrome.storage.local.get();

const authLink = setContext(async (_, { headers }) => {
const token = await getAuthToken();
return {
Expand All @@ -64,35 +46,17 @@ const getApolloClient = async () => {
};
});
const errorLink = onError(
({ graphQLErrors, networkError, forward, operation }) => {
({ graphQLErrors, networkError }) => {
if (isDefined(graphQLErrors)) {
for (const graphQLError of graphQLErrors) {
if (graphQLError.message === 'Unauthorized') {
return fromPromise(
renewToken(store.refreshToken.token)
.then((response) => {
if (isDefined(response)) {
setStore(response.renewToken.tokens);
}
})
.catch(() => {
clearStore();
}),
).flatMap(() => forward(operation));
clearStore();
return;
}
switch (graphQLError?.extensions?.code) {
case 'UNAUTHENTICATED': {
return fromPromise(
renewToken(store.refreshToken.token)
.then((response) => {
if (isDefined(response)) {
setStore(response.renewToken.tokens);
}
})
.catch(() => {
clearStore();
}),
).flatMap(() => forward(operation));
clearStore();
break;
}
default:
// eslint-disable-next-line no-console
Expand Down