move oauth api
This commit is contained in:
parent
7a02ae396e
commit
d2dcdfbd80
10 changed files with 204 additions and 281 deletions
|
|
@ -86,18 +86,20 @@ export const useAnnouncementsStore = defineStore('announcements', {
|
|||
}
|
||||
},
|
||||
markAnnouncementAsRead(id) {
|
||||
return this.userActions.dismissAnnouncement({
|
||||
id,
|
||||
credentials: useOAuthStore().token,
|
||||
}).then(() => {
|
||||
const index = this.announcements.findIndex((a) => a.id === id)
|
||||
return this.userActions
|
||||
.dismissAnnouncement({
|
||||
id,
|
||||
credentials: useOAuthStore().token,
|
||||
})
|
||||
.then(() => {
|
||||
const index = this.announcements.findIndex((a) => a.id === id)
|
||||
|
||||
if (index < 0) {
|
||||
return
|
||||
}
|
||||
if (index < 0) {
|
||||
return
|
||||
}
|
||||
|
||||
this.announcements[index].read = true
|
||||
})
|
||||
this.announcements[index].read = true
|
||||
})
|
||||
},
|
||||
startFetchingAnnouncements() {
|
||||
if (this.fetchAnnouncementsTimer) {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,8 @@ import { defineStore } from 'pinia'
|
|||
|
||||
import { useInstanceStore } from 'src/stores/instance.js'
|
||||
|
||||
import {
|
||||
createApp,
|
||||
getClientToken,
|
||||
verifyAppToken,
|
||||
} from 'src/services/new_api/oauth.js'
|
||||
import { createApp, getClientToken } from 'src/api/oauth.js'
|
||||
import { verifyCredentials } from 'src/api/public.js'
|
||||
|
||||
// status codes about verifyAppToken (GET /api/v1/apps/verify_credentials)
|
||||
const isAppTokenRejected = (error) =>
|
||||
|
|
@ -61,9 +58,9 @@ export const useOAuthStore = defineStore('oauth', {
|
|||
},
|
||||
async createApp() {
|
||||
const instance = useInstanceStore().server
|
||||
const app = await createApp(instance)
|
||||
this.setClientData(app)
|
||||
return app
|
||||
const app = await createApp({ instance })
|
||||
this.setClientData(app.data)
|
||||
return app.data
|
||||
},
|
||||
/// Use this if you want to get the client id and secret but are not interested
|
||||
/// in whether they are valid.
|
||||
|
|
@ -85,7 +82,7 @@ export const useOAuthStore = defineStore('oauth', {
|
|||
clientSecret: this.clientSecret,
|
||||
instance,
|
||||
})
|
||||
this.setAppToken(res.access_token)
|
||||
this.setAppToken(res.data.access_token)
|
||||
return res.access_token
|
||||
},
|
||||
/// Use this if you want to ensure the app is still valid to use.
|
||||
|
|
@ -93,9 +90,8 @@ export const useOAuthStore = defineStore('oauth', {
|
|||
async ensureAppToken() {
|
||||
if (this.appToken) {
|
||||
try {
|
||||
await verifyAppToken({
|
||||
instance: useInstanceStore().server,
|
||||
appToken: this.appToken,
|
||||
await verifyCredentials({
|
||||
credentials: this.appToken,
|
||||
})
|
||||
return this.appToken
|
||||
} catch (e) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue