|
|
@ -37,7 +37,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => { |
|
|
|
const { allRoles } = useRoles() |
|
|
|
const { allRoles } = useRoles() |
|
|
|
|
|
|
|
|
|
|
|
/** if user isn't signed in and google auth is enabled, try to check if sign-in data is present */ |
|
|
|
/** if user isn't signed in and google auth is enabled, try to check if sign-in data is present */ |
|
|
|
if (!state.signedIn && state.appInfo.value.googleAuthEnabled) await tryGoogleAuth(api, state.signIn) |
|
|
|
if (!state.signedIn.value && state.appInfo.value.googleAuthEnabled) await tryGoogleAuth(api, state.signIn) |
|
|
|
|
|
|
|
|
|
|
|
/** if public allow all visitors */ |
|
|
|
/** if public allow all visitors */ |
|
|
|
if (to.meta.public) return |
|
|
|
if (to.meta.public) return |
|
|
@ -89,22 +89,26 @@ export default defineNuxtRouteMiddleware(async (to, from) => { |
|
|
|
* If present, try using google auth data to sign user in before navigating to the next page |
|
|
|
* If present, try using google auth data to sign user in before navigating to the next page |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async function tryGoogleAuth(api: Api<any>, signIn: Actions['signIn']) { |
|
|
|
async function tryGoogleAuth(api: Api<any>, signIn: Actions['signIn']) { |
|
|
|
if (window.location.search && /\bscope=|\bstate=/.test(window.location.search) && /\bcode=/.test(window.location.search)) { |
|
|
|
if (process.client) { |
|
|
|
try { |
|
|
|
if (window.location.search && /\bscope=|\bstate=/.test(window.location.search) && /\bcode=/.test(window.location.search)) { |
|
|
|
const { |
|
|
|
try { |
|
|
|
data: { token }, |
|
|
|
const { |
|
|
|
} = await api.instance.post( |
|
|
|
data: { token }, |
|
|
|
`/auth/${window.location.search.includes('state=github') ? 'github' : 'google'}/genTokenByCode${window.location.search}`, |
|
|
|
} = await api.instance.post( |
|
|
|
) |
|
|
|
`/auth/${window.location.search.includes('state=github') ? 'github' : 'google'}/genTokenByCode${ |
|
|
|
|
|
|
|
window.location.search |
|
|
|
|
|
|
|
}`,
|
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
signIn(token) |
|
|
|
signIn(token) |
|
|
|
} catch (e: any) { |
|
|
|
} catch (e: any) { |
|
|
|
if (e.response && e.response.data && e.response.data.msg) { |
|
|
|
if (e.response && e.response.data && e.response.data.msg) { |
|
|
|
message.error({ content: e.response.data.msg }) |
|
|
|
message.error({ content: e.response.data.msg }) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const newURL = window.location.href.split('?')[0] |
|
|
|
const newURL = window.location.href.split('?')[0] |
|
|
|
window.history.pushState('object', document.title, newURL) |
|
|
|
window.history.pushState('object', document.title, newURL) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|