You've already forked AstralRinth
forked from didirus/AstralRinth
More secure custom authentication solution (#126)
* Remove Nuxt Auth from the project, and switch to a custom solution * Replace old testing code * Remove warnings * Add comments to hard to understand function calls in middleware * Use arrow functions
This commit is contained in:
53
store/auth.js
Normal file
53
store/auth.js
Normal file
@@ -0,0 +1,53 @@
|
||||
export const state = () => ({
|
||||
user: {},
|
||||
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)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user