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

ui: Refresh auth token for plugin flow on 401 (PROJQUAY-5390) #1843

Merged
merged 1 commit into from Apr 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions web/src/libs/axios.ts
Expand Up @@ -6,7 +6,6 @@ if (process.env.MOCK_API === 'true') {
require('src/tests/fake-db/ApiMock');
}


axios.defaults.withCredentials = true;
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

Expand Down Expand Up @@ -46,10 +45,16 @@ axiosIns.interceptors.response.use(
(response) => {
return response;
},
(error) => {
// TODO: Handle 401 errors for plugin
async (error) => {
if (error.response?.status === 401) {
window.location.href = '/signin';
if (window?.insights?.chrome?.auth) {
// refresh token for plugin
GlobalAuthState.bearerToken =
await window.insights.chrome.auth.getToken();
} else {
// redirect to login page for standalone
window.location.href = '/signin';
}
}
throw error; // Rethrow error to be handled in components
},
Expand Down
1 change: 0 additions & 1 deletion web/src/routes/PluginMain.tsx
Expand Up @@ -69,7 +69,6 @@ function PluginMain() {
const [isConfirmUserModalOpen, setConfirmUserModalOpen] = useState(false);

chrome?.auth?.getToken().then((token) => {
console.log('chrome auth token', token);
GlobalAuthState.bearerToken = token;
});

Expand Down