nuxt/auth

This commit is contained in:
ronger 2022-10-29 22:18:17 +08:00
parent 7c243e7d67
commit 7222753d0a
6 changed files with 16 additions and 11 deletions

View File

@ -76,7 +76,7 @@ export default {
redirect: {
login: '/login',
logout: false,
home: false
home: '/'
},
strategies: {
local: {

View File

@ -194,7 +194,7 @@ export default {
isMobile: state => state.global.isMobile,
loggedIn: state => state.auth.loggedIn,
user: state => state.auth.user,
avatar: state => state.auth.user.avatarUrl
avatar: state => state.auth.user?.avatarUrl
}),
hasPermissions() {
let account = this.$store.state.auth.user?.nickname;

View File

@ -91,7 +91,7 @@
return true;
}
}
return this.$auth.hasScope('blog_admin');
return this.$auth.hasScope('blog_admin') || this.$auth.hasScope('admin');
}
},
data() {

View File

@ -57,6 +57,7 @@ import {mapState} from 'vuex';
export default {
name: "login",
middleware: 'auth',
auth: 'guest',
data() {
return {
user: {
@ -93,10 +94,6 @@ export default {
_ts.$auth.setUserToken(response.data.token, response.data.refreshToken);
if (_ts.historyUrl) {
window.location.href = _ts.historyUrl
} else {
_ts.$router.push({
name: 'index'
})
}
}
_ts.$set(_ts, 'loginLoading', false);
@ -144,8 +141,14 @@ export default {
}
},
mounted() {
this.$store.commit('setActiveMenu', 'login');
this.$set(this, 'historyUrl', this.$route.query.historyUrl || '');
let _ts = this
_ts.$store.commit('setActiveMenu', 'login');
_ts.$set(_ts, 'historyUrl', _ts.$route.query.historyUrl || '');
// if (_ts.$auth.loggedIn) {
// _ts.$router.push({
// name: 'index'
// })
// }
}
}
</script>

View File

@ -22,7 +22,8 @@ export default {
topic => topic.topicUri === params.topic_uri
)
},
fetch({store, params, query}) {
fetch() {
let {store, params, query} = this.$nuxt.context
params.page = query.page || 1
return Promise.all([
store.dispatch('article/fetchList', params)

View File

@ -8,7 +8,8 @@ export const OPEN_DATA_API_PATH = '/api/open-data'
const getDefaultDashboardData = () => {
return {
dashboard: {}
countUserNum: 0,
countArticleNum: 0
}
}