Modrinth/store/auth.js
2021-03-29 18:14:06 -07:00

54 lines
1.0 KiB
JavaScript

export const state = () => ({
user: null,
userFollows: [],
token: '',
headers: {},
})
export const mutations = {
SET_USER(state, user) {
state.user = user
},
SET_USER_FOLLOWS(state, follows) {
state.userFollows = follows
},
SET_TOKEN(state, token) {
state.token = token
},
SET_HEADERS(state, headers) {
state.headers = headers
},
}
export const actions = {
async fetchUser({ commit }, { token }) {
const user = (
await this.$axios.get(`https://api.modrinth.com/api/v1/user`, {
headers: {
Authorization: token,
},
})
).data
commit('SET_USER', user)
commit('SET_TOKEN', token)
commit('SET_HEADERS', {
headers: {
Authorization: token,
},
})
},
async fetchUserFollows({ commit }, { userId, token }) {
const follows = await this.$axios.get(
`https://api.modrinth.com/api/v1/user/${userId}/follows`,
{
headers: {
Authorization: token,
},
}
)
commit('SET_USER_FOLLOWS', follows)
},
}