* adjust existing sign-in flow * test fetching of oauth client * allow for apiversion override * getAuthUrl refactor * Adjust auth to accept complex url redirections * introduce scopes * accept oauth flow * rename login/oauth to authorize * conform to labrinth spec and oauth2 spec * use cute icons for scope items * applications pages * Modal for copy client secret on creation * rip out old state * add authorizations * add flow error state and implement feedback * implement error notifications on error * Client secret modal flow aligned with PAT copy * Authorized scopes now aligned with Authorize screen * Fix spelling and capitalization * change redirect uris to include the input field * refactor 2fa flow to be more stable * visual adjustments for authorizations * Fix empty field submission bug * Add file upload for application icon * Change shape of editing/create application * replace icon with Avatar component * Refactor authorization card styling * UI feedback * clean up spacing, styling * Create a "Developer" section of user settings * Fix spacing and scope access * app description and url implementations * clean up imports * Update authorization endpoint * Update placeholder URL in applications.vue * Remove app information from authorization page * Remove max scopes from application settings * Fix import statement and update label styles * Replace useless headers * Update pages/auth/authorize.vue Co-authored-by: Calum H. <contact@mineblock11.dev> * Update pages/auth/authorize.vue Co-authored-by: Calum H. <contact@mineblock11.dev> * Finish PR --------- Co-authored-by: Calum H. <contact@mineblock11.dev> Co-authored-by: Jai A <jaiagr+gpg@pm.me>
106 lines
2.0 KiB
JavaScript
106 lines
2.0 KiB
JavaScript
export const useAuth = async (oldToken = null) => {
|
|
const auth = useState('auth', () => ({
|
|
user: null,
|
|
token: '',
|
|
headers: {},
|
|
}))
|
|
|
|
if (!auth.value.user || oldToken) {
|
|
auth.value = await initAuth(oldToken)
|
|
}
|
|
|
|
return auth
|
|
}
|
|
|
|
export const initAuth = async (oldToken = null) => {
|
|
const auth = {
|
|
user: null,
|
|
token: '',
|
|
}
|
|
|
|
if (oldToken === 'none') {
|
|
return auth
|
|
}
|
|
|
|
const route = useRoute()
|
|
const authCookie = useCookie('auth-token', {
|
|
maxAge: 60 * 60 * 24 * 365 * 10,
|
|
sameSite: 'lax',
|
|
secure: true,
|
|
httpOnly: false,
|
|
path: '/',
|
|
})
|
|
|
|
if (oldToken) {
|
|
authCookie.value = oldToken
|
|
}
|
|
|
|
if (route.query.code && !route.fullPath.includes('new_account=true')) {
|
|
authCookie.value = route.query.code
|
|
}
|
|
|
|
if (authCookie.value) {
|
|
auth.token = authCookie.value
|
|
|
|
if (!auth.token || !auth.token.startsWith('mra_')) {
|
|
return auth
|
|
}
|
|
|
|
try {
|
|
auth.user = await useBaseFetch(
|
|
'user',
|
|
{
|
|
headers: {
|
|
Authorization: auth.token,
|
|
},
|
|
},
|
|
true
|
|
)
|
|
} catch {}
|
|
}
|
|
|
|
if (!auth.user && auth.token) {
|
|
try {
|
|
const session = await useBaseFetch(
|
|
'session/refresh',
|
|
{
|
|
method: 'POST',
|
|
headers: {
|
|
Authorization: auth.token,
|
|
},
|
|
},
|
|
true
|
|
)
|
|
|
|
auth.token = session.session
|
|
authCookie.value = auth.token
|
|
|
|
auth.user = await useBaseFetch(
|
|
'user',
|
|
{
|
|
headers: {
|
|
Authorization: auth.token,
|
|
},
|
|
},
|
|
true
|
|
)
|
|
} catch {
|
|
authCookie.value = null
|
|
}
|
|
}
|
|
|
|
return auth
|
|
}
|
|
|
|
export const getAuthUrl = (provider, redirect = '') => {
|
|
const config = useRuntimeConfig()
|
|
const route = useRoute()
|
|
|
|
if (redirect === '') {
|
|
redirect = route.path
|
|
}
|
|
const fullURL = `${config.public.siteUrl}${redirect}`
|
|
|
|
return `${config.public.apiBaseUrl}auth/init?url=${fullURL}&provider=${provider}`
|
|
}
|