mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-05 02:34:56 +02:00
Fix dynamic route requests, add auth middleware
This commit is contained in:
parent
f83c5dd440
commit
bf38004b5e
11 changed files with 29 additions and 25 deletions
|
@ -10,6 +10,7 @@
|
|||
|
||||
<script>
|
||||
export default {
|
||||
middleware: 'authenticated',
|
||||
data() {
|
||||
return {
|
||||
socket: null
|
||||
|
@ -140,11 +141,6 @@ export default {
|
|||
this.socket.on('scan_progress', this.scanProgress)
|
||||
}
|
||||
},
|
||||
beforeMount() {
|
||||
if (!this.$store.state.user.user) {
|
||||
this.$router.replace(`/login?redirect=${this.$route.path}`)
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.initializeSocket()
|
||||
}
|
||||
|
|
6
client/middleware/authenticated.js
Normal file
6
client/middleware/authenticated.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
export default function ({ store, redirect, route }) {
|
||||
// If the user is not authenticated
|
||||
if (!store.state.user.user) {
|
||||
return redirect(`/login?redirect=${route.path}`)
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "audiobookshelf-client",
|
||||
"version": "0.9.7-beta",
|
||||
"version": "0.9.71-beta",
|
||||
"description": "Audiobook manager and player",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -34,16 +34,11 @@ export default {
|
|||
watch: {
|
||||
user(newVal) {
|
||||
if (newVal) {
|
||||
// if (process.env.NODE_ENV !== 'production') {
|
||||
if (this.$route.query.redirect) {
|
||||
this.$router.replace(this.$route.query.redirect)
|
||||
} else {
|
||||
this.$router.replace('/')
|
||||
}
|
||||
|
||||
// } else {
|
||||
// window.location.reload()
|
||||
// }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -56,7 +51,7 @@ export default {
|
|||
async submitForm() {
|
||||
this.error = null
|
||||
this.processing = true
|
||||
// var uri = `${process.env.serverUrl}/auth`
|
||||
|
||||
var payload = {
|
||||
username: this.username,
|
||||
password: this.password || ''
|
||||
|
|
|
@ -39,7 +39,11 @@ export const getters = {
|
|||
}
|
||||
|
||||
export const actions = {
|
||||
load({ commit }) {
|
||||
load({ commit, rootState }) {
|
||||
if (!rootState.user || !rootState.user.user) {
|
||||
console.error('audiobooks/load - User not set')
|
||||
return
|
||||
}
|
||||
this.$axios
|
||||
.$get(`/api/audiobooks`)
|
||||
.then((data) => {
|
||||
|
|
|
@ -48,10 +48,12 @@ export const actions = {
|
|||
export const mutations = {
|
||||
setUser(state, user) {
|
||||
state.user = user
|
||||
if (user && user.token) {
|
||||
localStorage.setItem('token', user.token)
|
||||
} else if (user) {
|
||||
if (user) {
|
||||
if (user.token) localStorage.setItem('token', user.token)
|
||||
console.log('setUser', user.username)
|
||||
} else {
|
||||
localStorage.removeItem('token')
|
||||
console.warn('setUser cleared')
|
||||
}
|
||||
},
|
||||
setSettings(state, settings) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue