minimal working
This commit is contained in:
1 parent
2093433b96
commit
13ea8c80da
11 files changed
+727
-337
No files matched your search
+12
-18
@@ -1,5 +1,7 @@
|
||||
import _axios, { AxiosInstance } from 'axios'
|
||||
|
||||
const WANIKANI_API_KEY = 'WANIKANI_API_KEY'
|
||||
|
||||
export type ITypeLevel = 'character' | 'vocabulary'
|
||||
export type IType = ITypeLevel | 'sentence'
|
||||
|
||||
@@ -93,35 +95,27 @@ class Api {
|
||||
}
|
||||
|
||||
async setWanikaniApiKey(apiKey?: string) {
|
||||
apiKey = apiKey || localStorage.getItem(WANIKANI_API_KEY) || ''
|
||||
console.log(apiKey)
|
||||
|
||||
const setApiKey = () => {
|
||||
if (apiKey) {
|
||||
this.axios.defaults.headers.common['Authorization'] = `Bearer ${apiKey}`
|
||||
localStorage.setItem(WANIKANI_API_KEY, apiKey)
|
||||
} else {
|
||||
delete this.axios.defaults.headers.common['Authorization']
|
||||
localStorage.removeItem(WANIKANI_API_KEY)
|
||||
}
|
||||
}
|
||||
|
||||
setApiKey()
|
||||
const r = await window.$nuxt.$accessor.updateSettings()
|
||||
|
||||
return await this.isAuthorized().then((r) => {
|
||||
if (!r) {
|
||||
apiKey = ''
|
||||
setApiKey()
|
||||
}
|
||||
return r
|
||||
})
|
||||
}
|
||||
|
||||
async isAuthorized(): Promise<boolean> {
|
||||
if (this._isAuthorized && !this._user) {
|
||||
const r = await this.user_getSettings({ select: ['identifier'] })
|
||||
if (r) {
|
||||
this._user = r.identifier
|
||||
this._isAuthorized = true
|
||||
}
|
||||
if (!r) {
|
||||
apiKey = ''
|
||||
setApiKey()
|
||||
}
|
||||
|
||||
return this._isAuthorized
|
||||
return r
|
||||
}
|
||||
|
||||
async user_getSettings(params: { select: (keyof IUserSettings)[] }) {
|
||||
|
||||
Reference in new issue
Block a user