chore: add eslint and fix lint errors

This commit is contained in:
2020-01-25 14:59:14 +01:00
parent e6c87e2f46
commit ef2015f012
36 changed files with 1645 additions and 917 deletions
+63 -65
View File
@@ -1,9 +1,9 @@
import { ApolloClient } from 'apollo-client'
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory';
import { InMemoryCache } from 'apollo-cache-inmemory'
import { setContext } from 'apollo-link-context'
import { useAuth } from './auth'
import { reactive, toRefs } from '@vue/composition-api'
import useAuth from './auth'
let instance = null
@@ -13,23 +13,22 @@ const httpLink = createHttpLink({
uri: apiUrl
})
const getToken = async (options) => {
const getToken = async options => {
const { getTokenSilently, isAuthenticated } = useAuth()
if (isAuthenticated.value) {
return await getTokenSilently.value(options)
} else {
return options
return getTokenSilently.value(options)
}
};
return options
}
const authLink = setContext(async (_, { headers }) => {
const token = await getToken()
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
authorization: token ? `Bearer ${token}` : ''
}
};
}
})
const client = new ApolloClient({
@@ -37,84 +36,83 @@ const client = new ApolloClient({
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
fetchPolicy: 'cache-and-network',
},
},
fetchPolicy: 'cache-and-network'
}
}
})
instance = client
export const useMutation = (mutation, options) => {
const opts = options;
const doMutate = options => new Promise((resolve, reject) => {
out.loading = true
instance.mutate({
mutation,
...opts,
...options
})
.then(result => {
out.loading = false
out.data = result.data
resolve(result)
})
.catch(e => {
out.loading = false
out.error = e
reject(e)
})
})
const out = reactive({
data: {},
error: null,
loading: false,
loading: false
})
const doMutate = mutateOptions =>
new Promise((resolve, reject) => {
out.loading = true
instance
.mutate({
mutation,
...options,
...mutateOptions
})
.then(result => {
out.loading = false
out.data = result.data
resolve(result)
})
.catch(e => {
out.loading = false
out.error = e
reject(e)
})
})
return [doMutate, toRefs(out)]
}
export const useLazyQuery = (query, options) => {
const opts = options
let watchedQuery = null
const doQuery = options => new Promise((resolve, reject) => {
out.loading = true
let effectiveOptions = {
query,
...(opts || {}),
...(options || {})
}
watchedQuery = instance.watchQuery(effectiveOptions)
watchedQuery.subscribe(({loading, data}) => {
out.loading = loading
out.data = data || {}
out.error = null
resolve(data)
}, error => {
out.loading = false
out.error = error
reject(error)
})
const out = reactive({
data: {},
error: null,
loading: false
})
const refetch = variables => {
const doQuery = queryOptions =>
new Promise((resolve, reject) => {
out.loading = true
const effectiveOptions = {
query,
...(options || {}),
...(queryOptions || {})
}
watchedQuery = instance.watchQuery(effectiveOptions)
watchedQuery.subscribe(
({ loading, data }) => {
out.loading = loading
out.data = data || {}
out.error = null
resolve(data)
},
error => {
out.loading = false
out.error = error
reject(error)
}
)
})
out.refetch = variables => {
const opts = {}
if (variables) (
opts.variables = variables
)
if (variables) opts.variables = variables
doQuery(opts)
}
const startPolling = interval => doQuery({pollInterval: interval})
const stopPolling = () => {
out.startPolling = interval => doQuery({ pollInterval: interval })
out.stopPolling = () => {
if (watchedQuery) {
watchedQuery.stopPolling()
}
}
const out = reactive({
data: {},
error: null,
loading: false,
refetch,
startPolling,
stopPolling
})
return [doQuery, toRefs(out)]
}
+55 -59
View File
@@ -3,23 +3,23 @@ import { reactive, toRefs } from '@vue/composition-api'
/** Define a default action to perform after authentication */
const DEFAULT_REDIRECT_CALLBACK = () =>
window.history.replaceState({}, document.title, window.location.pathname);
window.history.replaceState({}, document.title, window.location.pathname)
let instance;
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)
}
const options = {
domain: domain,
domain,
client_id: 'orQfnvCPUR5C3mJkKoiWLQHOVQsBn60e',
audience: 'http://dancefinder.unbound.se',
redirect_uri: window.location.origin,
redirect_uri: window.location.origin
}
instance = reactive({
@@ -31,95 +31,91 @@ export const useAuth = (onRedirectCallback = DEFAULT_REDIRECT_CALLBACK) => {
error: null,
/** Authenticates the user using a popup window */
loginWithPopup: async o => {
this.popupOpen = true;
this.popupOpen = true
try {
await instance.auth0Client.loginWithPopup(o);
await instance.auth0Client.loginWithPopup(o)
} catch (e) {
// eslint-disable-next-line
console.error(e);
} finally {
instance.popupOpen = false;
instance.popupOpen = false
}
instance.user = await instance.auth0Client.getUser();
instance.isAuthenticated = true;
instance.user = await instance.auth0Client.getUser()
instance.isAuthenticated = true
},
/** Handles the callback when logging in using a redirect */
handleRedirectCallback: async () => {
instance.loading = true;
instance.loading = true
try {
await instance.auth0Client.handleRedirectCallback();
instance.user = await instance.auth0Client.getUser();
instance.isAuthenticated = true;
await instance.auth0Client.handleRedirectCallback()
instance.user = await instance.auth0Client.getUser()
instance.isAuthenticated = true
} catch (e) {
instance.error = e;
instance.error = e
} finally {
instance.loading = false;
instance.loading = false
}
},
/** Authenticates the user using the redirect method */
loginWithRedirect: o => {
return instance.auth0Client.loginWithRedirect(o);
return instance.auth0Client.loginWithRedirect(o)
},
/** Returns all the claims present in the ID token */
getIdTokenClaims: o => {
return instance.auth0Client.getIdTokenClaims(o);
return instance.auth0Client.getIdTokenClaims(o)
},
/** Returns the access token. If the token is invalid or missing, a new one is retrieved */
getTokenSilently: o => {
return instance.auth0Client.getTokenSilently(o);
return instance.auth0Client.getTokenSilently(o)
},
/** Gets the access token using a popup window */
getTokenWithPopup: o => {
return instance.auth0Client.getTokenWithPopup(o);
return instance.auth0Client.getTokenWithPopup(o)
},
/** Logs the user out and removes their session on the authorization server */
logout: o => {
return instance.auth0Client.logout(o);
return instance.auth0Client.logout(o)
}
})
const fetchUser = () => {
instance.auth0Client.isAuthenticated()
.then(a => {
instance.isAuthenticated = a
instance.auth0Client.getUser()
.then(u => {
instance.user = u
instance.loading = false;
});
});
}
// Create a new instance of the SDK client using members of the given options object
createAuth0Client(options)
.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=')
) {
// handle the redirect and retrieve tokens
instance.auth0Client.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()
})
} else {
fetchUser()
}
} catch (e) {
instance.error = e;
} finally {
instance.auth0Client.isAuthenticated().then(a => {
instance.isAuthenticated = a
instance.auth0Client.getUser().then(u => {
instance.user = u
instance.loading = false
}
})
})
}
// Create a new instance of the SDK client using members of the given options object
createAuth0Client(options).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=')
) {
// handle the redirect and retrieve tokens
instance.auth0Client.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()
})
} else {
fetchUser()
}
} catch (e) {
instance.error = e
} finally {
instance.loading = false
}
})
return toRefs(instance)
}
+3 -3
View File
@@ -1,4 +1,4 @@
import Vue from 'vue';
import VueCompositionApi from '@vue/composition-api';
import Vue from 'vue'
import VueCompositionApi from '@vue/composition-api'
Vue.use(VueCompositionApi);
Vue.use(VueCompositionApi)
+3 -3
View File
@@ -1,4 +1,4 @@
import Vue from 'vue';
import hooks from '@u3u/vue-hooks';
import Vue from 'vue'
import hooks from '@u3u/vue-hooks'
Vue.use(hooks);
Vue.use(hooks)
+1 -1
View File
@@ -8,7 +8,7 @@ export const useTranslation = () => {
}
}
export default ({app}) => {
export default ({ app }) => {
i18n = app.i18n
localePath = app.localePath
}
+2 -2
View File
@@ -1,5 +1,5 @@
import Vue from 'vue'
import vueNumeralFilterInstaller from 'vue-numeral-filter';
import vueNumeralFilterInstaller from 'vue-numeral-filter'
// TODO: Switch to sv-se when PR (https://github.com/adamwdraper/Numeral-js/pull/534) is merged
Vue.use(vueNumeralFilterInstaller, { locale: 'no' });
Vue.use(vueNumeralFilterInstaller, { locale: 'no' })
+1 -1
View File
@@ -1,4 +1,4 @@
import Vue from 'vue'
import Vuetify from 'vuetify'
Vue.use(Vuetify);
Vue.use(Vuetify)