Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
K
kiaisoft_tuananh_nuxt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TTS Tran Viet Anh
kiaisoft_tuananh_nuxt
Commits
205c8dde
Commit
205c8dde
authored
Feb 06, 2023
by
Le Dinh Trung
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'hotfix/axios-api' into 'dev'
Hotfix/axios api See merge request
!15
parents
9a6040a1
035cdff9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
45 deletions
+41
-45
Navbar.vue
components/Navbar.vue
+18
-14
login.vue
pages/login.vue
+17
-26
axios.js
plugins/axios.js
+6
-5
No files found.
components/Navbar.vue
View file @
205c8dde
...
@@ -43,22 +43,26 @@
...
@@ -43,22 +43,26 @@
export
default
{
export
default
{
methods
:
{
methods
:
{
logout
()
{
async
logout
()
{
fetch
(
'
http://127.0.0.1:8000/api/logout
'
,
{
try
{
method
:
'
POST
'
,
const
resp
=
await
this
.
$axios
.
post
(
'
/logout
'
,
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
accept
:
'
application/json
'
},
body
:
JSON
.
stringify
({
token
:
this
.
$auth
.
$storage
.
getUniversal
(
'
token
'
)
token
:
this
.
$auth
.
$storage
.
getUniversal
(
'
token
'
)
})
})
})
if
(
resp
.
status
==
'
200
'
)
{
localStorage
.
setItem
(
'
token
'
,
''
)
this
.
$toast
.
success
(
'
Logout!
'
,
{
this
.
$auth
.
$storage
.
setUniversal
(
'
loggedIn
'
,
'
false
'
)
duration
:
2000
this
.
$auth
.
$storage
.
setUniversal
(
'
token
'
,
''
)
})
this
.
$auth
.
$storage
.
setUniversal
(
'
userName
'
,
''
)
this
.
$router
.
push
(
'
/login
'
)
this
.
$router
.
push
(
'
/login
'
)
localStorage
.
setItem
(
'
token
'
,
''
)
this
.
$auth
.
$storage
.
setUniversal
(
'
loggedIn
'
,
'
false
'
)
this
.
$auth
.
$storage
.
setUniversal
(
'
token
'
,
''
)
this
.
$auth
.
$storage
.
setUniversal
(
'
userName
'
,
''
)
}
}
catch
(
e
)
{
this
.
$toast
.
error
(
'
ERR !
'
,
{
duration
:
2000
})
}
}
}
}
}
}
}
...
...
pages/login.vue
View file @
205c8dde
...
@@ -109,41 +109,32 @@ export default {
...
@@ -109,41 +109,32 @@ export default {
this
.
password
=
''
this
.
password
=
''
this
.
checkbox
=
false
this
.
checkbox
=
false
},
},
async
login
()
{
async
login
()
{
try
{
try
{
const
resp
=
await
fetch
(
'
http://127.0.0.1:8000/api/login
'
,
{
const
resp
=
await
this
.
$axios
.
post
(
'
/login
'
,
method
:
'
POST
'
,
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
Accept
:
'
application/json
'
},
body
:
JSON
.
stringify
({
email
:
this
.
email
,
email
:
this
.
email
,
password
:
this
.
password
,
password
:
this
.
password
,
status
:
this
.
status
status
:
this
.
status
})
})
}).
then
((
response
)
=>
{
localStorage
.
setItem
(
"
token
"
,
resp
.
data
.
data
.
bearer_token
)
return
response
.
json
()
this
.
$auth
.
$storage
.
setUniversal
(
"
token
"
,
resp
.
data
.
data
.
bearer_token
)
})
this
.
$auth
.
$storage
.
setUniversal
(
"
userName
"
,
resp
.
data
.
data
.
name
)
console
.
log
(
resp
.
status
)
this
.
$auth
.
$storage
.
setUniversal
(
"
loggedIn
"
,
"
true
"
)
localStorage
.
setItem
(
'
token
'
,
'
Bearer
'
+
resp
.
data
.
bearer_token
)
if
(
resp
.
status
==
"
200
"
)
{
this
.
$auth
.
$storage
.
setUniversal
(
'
token
'
,
'
Bearer
'
+
resp
.
data
.
bearer_token
)
this
.
$toast
.
success
(
"
Successfully authenticated
"
,
{
this
.
$auth
.
$storage
.
setUniversal
(
'
userName
'
,
resp
.
data
.
name
)
duration
:
2000
,
this
.
$auth
.
$storage
.
setUniversal
(
'
loggedIn
'
,
'
true
'
)
});
if
(
resp
.
status
==
'
success
'
)
{
this
.
$router
.
push
(
"
home
"
);
this
.
$toast
.
success
(
'
Successfully authenticated
'
,
{
duration
:
2000
})
this
.
$router
.
push
(
'
home
'
)
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
$toast
.
error
(
'
Username or Password not valid
'
,
{
this
.
$toast
.
error
(
"
Username or Password not valid
"
,
{
duration
:
2000
duration
:
2000
,
})
})
;
this
.
$router
.
push
(
'
/login
'
)
this
.
$router
.
push
(
"
/login
"
);
}
}
}
}
}
}
}
}
</
script
>
</
script
>
<
style
scoped
>
<
style
scoped
>
...
...
plugins/axios.js
View file @
205c8dde
export
default
function
({
$axios
},
inject
,
redirect
)
{
export
default
function
({
$axios
},
inject
,
redirect
)
{
$axios
.
onError
(
error
=>
{
$axios
.
onError
(
(
error
)
=>
{
if
(
error
.
response
.
status
===
500
)
{
if
(
error
.
response
.
status
===
500
)
{
redirect
(
'
/500
'
)
redirect
(
'
/500
'
)
}
}
})
})
$axios
.
onError
(
error
=>
{
$axios
.
onError
(
(
error
)
=>
{
const
code
=
parseInt
(
error
.
response
&&
error
.
response
.
status
)
const
code
=
parseInt
(
error
.
response
&&
error
.
response
.
status
)
if
(
code
===
400
)
{
if
(
code
===
400
)
{
redirect
(
'
/400
'
)
redirect
(
'
/400
'
)
...
@@ -15,11 +15,12 @@ export default function ({ $axios }, inject, redirect) {
...
@@ -15,11 +15,12 @@ export default function ({ $axios }, inject, redirect) {
const
api
=
$axios
.
create
({
const
api
=
$axios
.
create
({
headers
:
{
headers
:
{
common
:
{
common
:
{
Accept
:
'
application/json, text/plain, */*
'
Accept
:
'
application/json, text/plain, */*
'
,
'
Content-Type
'
:
'
application/json, text/plain, */*
'
}
}
}
}
})
})
// Inject to context as $api
// Inject to context as $api
inject
(
'
api
'
,
api
)
inject
(
'
api
'
,
api
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment