Commit 65376418 authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

fix ident user

parent a43d2364
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
<b-collapse id="nav-collapse" is-nav> <b-collapse id="nav-collapse" is-nav>
<b-navbar-nav> <b-navbar-nav>
<b-nav-item href="/home/users">USER</b-nav-item> <b-nav-item href="/users">USER</b-nav-item>
<b-nav-item href="/home/categories">CATEGORY</b-nav-item> <b-nav-item href="/categories">CATEGORY</b-nav-item>
<b-nav-item href="/home/products">PRODUCT</b-nav-item> <b-nav-item href="/products">PRODUCT</b-nav-item>
<b-nav-item href="/home/posts">POST</b-nav-item> <b-nav-item href="/posts">POST</b-nav-item>
</b-navbar-nav> </b-navbar-nav>
<!-- Right aligned nav items --> <!-- Right aligned nav items -->
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
</template> </template>
<script> <script>
export default { export default {
name: "nav", name: "Nav",
}; };
</script> </script>
<script> <script>
...@@ -66,7 +66,7 @@ export default { ...@@ -66,7 +66,7 @@ export default {
this.$auth.$storage.setUniversal("loggedIn", "false"); this.$auth.$storage.setUniversal("loggedIn", "false");
this.$auth.$storage.setUniversal("token", ""); this.$auth.$storage.setUniversal("token", "");
this.$auth.$storage.setUniversal("userName", ""); this.$auth.$storage.setUniversal("userName", "");
this.$router.push("/"); this.$router.push("/login");
}, },
}, },
}; };
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
</template> </template>
<script> <script>
export default { export default {
name: "sidebar", name: "SideBar",
}; };
</script> </script>
<script> <script>
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
<Nav /> <Nav />
<nuxt /> <nuxt />
</div> </div>
</template> </template>
<script> <script>
import Nav from "@/components/Nav"; import Nav from "@/components/Nav";
import SideBar from "@/components/SideBar";
export default { export default {
components: { Nav }, components: { Nav },
......
export default ({ redirect }) => { export default ({ redirect }) => {
// console.log('[LOG]: middleware is running ...') // console.log('[LOG]: middleware is running ...')
if (localStorage.getItem("token")=="") { if (localStorage.getItem("token")=="") {
return redirect('/') return redirect('/login')
} }
}; };
\ No newline at end of file
...@@ -45,6 +45,7 @@ export default { ...@@ -45,6 +45,7 @@ export default {
'@nuxtjs/axios', '@nuxtjs/axios',
'@nuxtjs/auth-next', '@nuxtjs/auth-next',
'@nuxtjs/toast', '@nuxtjs/toast',
'@pinia/nuxt',
], ],
bootstrapVue: { bootstrapVue: {
...@@ -52,12 +53,23 @@ export default { ...@@ -52,12 +53,23 @@ export default {
}, },
axios: { axios: {
baseURL: process.env.API_URL || ' http://127.0.0.1:8000/api/', baseURL: 'http://127.0.0.1:8000/api/',
debug: process.env.DEBUG || false, debug: false,
proxyHeaders: false, proxyHeaders: true,
credentials: false, credentials: false,
}, },
// publicRuntimeConfig: {
// axios: {
// browserBaseURL: process.env.BROWSER_BASE_URL
// }
// },
// privateRuntimeConfig: {
// axios: {
// baseURL: process.env.BASE_URL
// }
// },
auth: { auth: {
}, },
......
This diff is collapsed.
...@@ -115,7 +115,7 @@ export default { ...@@ -115,7 +115,7 @@ export default {
this.$toast.error("Username or Password not valid", { this.$toast.error("Username or Password not valid", {
duration: 2000, duration: 2000,
}); });
this.$router.push("/"); this.$router.push("/login");
} }
}, },
checkForm: function (e) { checkForm: function (e) {
......
<template>
<div>content</div>
</template>
<script>
export default {
layout: "default",
};
</script>
<style>
</style>
\ No newline at end of file
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<b-breadcrumb-item href="/home/users">User</b-breadcrumb-item> <b-breadcrumb-item href="/home/users">User</b-breadcrumb-item>
</b-breadcrumb> </b-breadcrumb>
<div style="float: right"> <div style="float: right">
<b-button v-b-modal.modal-login >New User</b-button> <b-button v-b-modal.modal-login class="text-white">New User</b-button>
<!-- modal create user --> <!-- modal create user -->
<b-modal id="modal-login" title="Create User" class="modal fade" > <b-modal id="modal-login" title="Create User" class="modal fade" >
<Notification :message="error" v-if="error" /> <Notification :message="error" v-if="error" />
...@@ -255,15 +255,15 @@ export default { ...@@ -255,15 +255,15 @@ export default {
}, },
watch: { watch: {
dialog(val) { dialog(val) {
val || this.close(); val || this.close()
}, },
dialogDelete(val) { dialogDelete(val) {
val || this.closeDelete(); val || this.closeDelete()
}, },
}, },
created() { created() {
this.initialize(); this.initialize()
this.getUsers(); this.getUsers()
}, },
methods: { methods: {
initialize() { initialize() {
...@@ -271,44 +271,44 @@ export default { ...@@ -271,44 +271,44 @@ export default {
this.editedItem = {} this.editedItem = {}
}, },
editItem(item) { editItem(item) {
this.editedIndex = this.users.indexOf(item); this.editedIndex = this.users.indexOf(item)
this.editedItem = Object.assign({}, item); this.editedItem = Object.assign({}, item)
this.dialog = true; this.dialog = true
}, },
deleteItem(item) { deleteItem(item) {
this.editedIndex = this.users.indexOf(item); this.editedIndex = this.users.indexOf(item)
this.editedItem = Object.assign({}, item); this.editedItem = Object.assign({}, item)
this.dialogDelete = true; this.dialogDelete = true
}, },
deleteItemConfirm() { deleteItemConfirm() {
this.users.splice(this.editedIndex, 1); this.users.splice(this.editedIndex, 1)
this.closeDelete(); this.closeDelete()
}, },
close() { close() {
this.dialog = false; this.dialog = false
this.$nextTick(() => { this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem); this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1; this.editedIndex = -1
}); });
}, },
closeDelete() { closeDelete() {
this.dialogDelete = false; this.dialogDelete = false
this.$nextTick(() => { this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem); this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1; this.editedIndex = -1
}); });
}, },
save() { save() {
if (this.editedIndex > -1) { if (this.editedIndex > -1) {
Object.assign(this.users[this.editedIndex], this.editedItem); Object.assign(this.users[this.editedIndex], this.editedItem)
} else { } else {
this.users.push(this.editedItem); this.users.push(this.editedItem)
} }
this.close(); this.close();
}, },
getUsers() { getUsers() {
axios this.$axios
.get("http://127.0.0.1:8000/api/users/") .get('/users/')
.then((response) => (this.users = response.data.data.data)) .then((response) => (this.users = response.data.data.data))
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);
...@@ -316,8 +316,8 @@ export default { ...@@ -316,8 +316,8 @@ export default {
}, },
createUser() { createUser() {
const self = this const self = this
axios this.$axios
.post('http://127.0.0.1:8000/api/users/',{ .post('/users/',{
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
...@@ -339,8 +339,8 @@ export default { ...@@ -339,8 +339,8 @@ export default {
}) })
.catch(errors => { .catch(errors => {
this.$bvModal.hide('modal-login') this.$bvModal.hide('modal-login')
console.log(errors.response.data.message); console.log(errors.response.data.message)
this.message = errors.response.data.message; this.message = errors.response.data.message
self.$toast.error('something went wrong while trying create!',{ self.$toast.error('something went wrong while trying create!',{
duration: 3000 duration: 3000
}); });
...@@ -348,18 +348,17 @@ export default { ...@@ -348,18 +348,17 @@ export default {
}, },
deleteUser(userID, index) { deleteUser(userID, index) {
const self = this const self = this
this.editedIndex = this.users.indexOf(index); this.editedIndex = this.users.indexOf(index)
if(confirm("Do you really want to delete?")){ if(confirm("Do you really want to delete?")){
try{ try{
axios this.$axios
.delete(`http://127.0.0.1:8000/api/users/${userID}`) .delete(`/users/${userID}`)
.then(response => { .then(response => {
console.log(response.data) console.log(response.data)
this.users.splice(this.editedIndex, 1); this.users.splice(this.editedIndex, 1)
self.$toast.success('User deleted successfully!',{ self.$toast.success('User deleted successfully!',{
duration: 3000 duration: 3000
}); })
}) })
} catch(error){ } catch(error){
console.log(error) console.log(error)
...@@ -367,21 +366,21 @@ export default { ...@@ -367,21 +366,21 @@ export default {
} }
}, },
editUser(user) { editUser(user) {
this.$bvModal.show('modal-edit'); this.$bvModal.show('modal-edit')
this.eID = user.id; this.eID = user.id
this.eEmail = user.email; this.eEmail = user.email
this.eName = user.name; this.eName = user.name
this.editedIndex = this.users.indexOf(user); this.editedIndex = this.users.indexOf(user)
console.log(this?.eID); console.log(this?.eID)
}, },
updateUser(userID) { updateUser(userID) {
const self = this const self = this
console.log(this.eName); console.log(this.eName)
console.log(this.eEmail); console.log(this.eEmail)
console.log(this?.eID); console.log(this?.eID)
try{ try{
axios this.$axios
.put(`http://127.0.0.1:8000/api/users/${this?.eID}`,{ .put(`/users/${this?.eID}`,{
email: this.eEmail, email: this.eEmail,
password: this.ePassword, password: this.ePassword,
name:this.eName,} ) name:this.eName,} )
......
export default ({ $axios}) => { export default function ({ $axios }, inject) {
$axios.onRequest(config => {
config.headers.common['Content-Type'] = 'multipart/form-data'; const api = $axios.create({
}); headers: {
common: {
Accept: 'application/json, text/plain, */*'
}
}
})
// Set baseURL to something different
api.setBaseURL('http://127.0.0.1:8000/api/')
// Inject to context as $api
inject('api', api)
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment