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

fix ident user

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