fix: eslint errors

This commit is contained in:
2020-04-06 10:52:55 +02:00
parent cc9968bd06
commit b4191d1416
9 changed files with 145 additions and 118 deletions
+47 -41
View File
@@ -7,10 +7,10 @@ const DEFAULT_REDIRECT_CALLBACK = () =>
let instance
const params = (new URL(window.location)).searchParams
const params = new URL(window.location).searchParams
const domain = params.get('domain') || 'unbound.eu.auth0.com'
export const useAuth = (onRedirectCallback = DEFAULT_REDIRECT_CALLBACK) => {
export default (onRedirectCallback = DEFAULT_REDIRECT_CALLBACK) => {
if (instance) {
return toRefs(instance)
}
@@ -42,15 +42,21 @@ export const useAuth = (onRedirectCallback = DEFAULT_REDIRECT_CALLBACK) => {
instance.popupOpen = false
}
instance.user = await instance.auth0Client.then(client => client.getUser())
instance.user = await instance.auth0Client.then(client =>
client.getUser()
)
instance.isAuthenticated = true
},
/** Handles the callback when logging in using a redirect */
handleRedirectCallback: async () => {
instance.loading = true
try {
await instance.auth0Client.then(client => client.handleRedirectCallback())
instance.user = await instance.auth0Client.then(client => client.getUser())
await instance.auth0Client.then(client =>
client.handleRedirectCallback()
)
instance.user = await instance.auth0Client.then(client =>
client.getUser()
)
instance.isAuthenticated = true
} catch (e) {
instance.error = e
@@ -87,46 +93,46 @@ export const useAuth = (onRedirectCallback = DEFAULT_REDIRECT_CALLBACK) => {
.then(client => client.isAuthenticated())
.then(a => {
instance.isAuthenticated = a
instance.auth0Client
.then(client => client.getUser()
.then(u => {
instance.user = u
instance.loading = false
}))
instance.auth0Client.then(client =>
client.getUser().then(u => {
instance.user = u
instance.loading = false
})
)
})
}
// Create a new instance of the SDK client using members of the given options object
// Create a new instance of the SDK client using members of the given options object
instance.auth0Client = createAuth0Client(options)
instance.auth0Client
.then(client => {
instance.loading = true
// instance.auth0Client = client
try {
// If the user is returning to the app after authentication..
if (
window.location.search.includes('code=') &&
window.location.search.includes('state=')
) {
console.log('location search', window.location.search)
// handle the redirect and retrieve tokens
client.handleRedirectCallback()
.then(appState => {
// Notify subscribers that the redirect callback has happened, passing the appState
// (useful for retrieving any pre-authentication state)
onRedirectCallback(appState)
// Initialize our internal authentication state
fetchUser()
})
.catch(e => console.error('error handling redirect callback', e))
} else {
fetchUser()
}
} catch (e) {
instance.error = e
} finally {
instance.loading = false
instance.auth0Client.then(client => {
instance.loading = true
// instance.auth0Client = client
try {
// If the user is returning to the app after authentication..
if (
window.location.search.includes('code=') &&
window.location.search.includes('state=')
) {
console.log('location search', window.location.search)
// handle the redirect and retrieve tokens
client
.handleRedirectCallback()
.then(appState => {
// Notify subscribers that the redirect callback has happened, passing the appState
// (useful for retrieving any pre-authentication state)
onRedirectCallback(appState)
// Initialize our internal authentication state
fetchUser()
})
.catch(e => console.error('error handling redirect callback', e))
} else {
fetchUser()
}
})
} catch (e) {
instance.error = e
} finally {
instance.loading = false
}
})
return toRefs(instance)
}