From f1ada5b3292d45fed7eb808d8cc4d98573636e9b Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Thu, 5 Oct 2023 00:01:10 +0530 Subject: using dark mode if system is in dark mode --- src/main.ts | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src/main.ts') diff --git a/src/main.ts b/src/main.ts index 2886300..c3b6952 100644 --- a/src/main.ts +++ b/src/main.ts @@ -26,35 +26,42 @@ axios.interceptors.request.use( axios.interceptors.response.use( (res) => { - return res; + return res }, async (err) => { - const originalConfig = err.config; + const originalConfig = err.config - if (originalConfig.url !== "/auth/signin" && err.response) { + if (originalConfig.url !== '/auth/signin' && err.response) { if (err.response.status === 401 && !originalConfig._retry) { - originalConfig._retry = true; + originalConfig._retry = true try { - const rs = await axios.post("/auth/refresh", { - RefreshToken: localStorage.getItem("refToken") - }); + const rs = await axios.post('/auth/refresh', { + RefreshToken: localStorage.getItem('refToken') + }) - localStorage.setItem("authToken", rs.data.auth_token) + localStorage.setItem('authToken', rs.data.auth_token) - return axios(originalConfig); + return axios(originalConfig) } catch (_error) { - return Promise.reject(_error); + return Promise.reject(_error) } } } - return Promise.reject(err); + return Promise.reject(err) } -); +) const app = createApp(App) app.use(router) app.mount('#app') + +// use dark theme if system is in dark mode +// flaky +document.documentElement.setAttribute( + 'data-bs-theme', + window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' +) -- cgit v1.2.3