Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nuxtjschat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nguyễn Đức Huy
nuxtjschat
Commits
a417a8d8
Commit
a417a8d8
authored
Jan 11, 2021
by
Nguyễn Đức Huy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store all in vuex
parent
378b97db
Pipeline
#1170
failed with stages
in 0 seconds
Changes
6
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
15 deletions
+52
-15
layouts/default.vue
+7
-10
middleware/auth.js
+5
-0
nuxt.config.js
+2
-2
pages/login/index.vue
+1
-3
pages/my_page/index.vue
+20
-0
store/index.js
+17
-0
No files found.
layouts/default.vue
View file @
a417a8d8
...
...
@@ -5,18 +5,15 @@
<Logo
/>
</div>
<ul
id=
"navbar-child"
>
<li><nuxt-link
to=
"/"
>
Home
</nuxt-link></li>
<li><nuxt-link
to=
"/
ssss
"
>
Home
</nuxt-link></li>
<li><nuxt-link
to=
"/chat"
>
Chat Room
</nuxt-link></li>
<li><nuxt-link
to=
"/about"
>
About Me
</nuxt-link></li>
<li>
<!-- hi username -->
Hi
<!-- log out button -->
</li>
<li>
<li><nuxt-link
to=
"/my_page"
>
About Me
</nuxt-link></li>
<li
v-if=
"$store.getters.isAuth == true"
><nuxt-link
to=
"/login"
>
Logout
</nuxt-link></li>
<!--
<li>
-->
<!-- log in button -->
<
nuxt-link
to=
"/about"
>
{Not login yet}
</nuxt-link
>
<
/li
>
<
!--
<nuxt-link
to=
"/about"
>
{Not login yet}
</nuxt-link>
--
>
<
!--
</li>
--
>
</ul>
</div>
<div
class=
"default_nuxt"
>
...
...
middleware/auth.js
0 → 100644
View file @
a417a8d8
export
default
function
(
context
)
{
if
(
context
.
store
.
getters
.
isAuth
==
false
)
{
context
.
redirect
(
'/login'
)
}
}
nuxt.config.js
View file @
a417a8d8
...
...
@@ -36,8 +36,8 @@ export default {
// https://go.nuxtjs.dev/pwa
'@nuxtjs/pwa'
,
// https://go.nuxtjs.dev/content
'@nuxt/content'
,
'@nuxtjs/auth-next'
,
//
'@nuxt/content',
//
'@nuxtjs/auth-next',
],
// Axios module configuration (https://go.nuxtjs.dev/config-axios)
...
...
pages/login/index.vue
View file @
a417a8d8
...
...
@@ -72,13 +72,11 @@ export default {
// })
// },
onSubmit
()
{
this
.
$store
.
dispatch
(
'authenticationUser'
,
{
this
.
$store
.
dispatch
(
'authenticationUser'
,
{
email
:
this
.
email
,
password
:
this
.
password
,
checkLogin
:
this
.
checkLogin
,
})
// .then(() => this.$router.push('/success_goi_nha'))
},
},
}
...
...
pages/my_page/index.vue
0 → 100644
View file @
a417a8d8
<
template
>
<div
class=
"container"
>
Hello
{{
this
.
$store
.
state
.
token
}}
</div>
</
template
>
<
script
>
export
default
{
middleware
:
'auth'
,
}
</
script
>
<
style
scope
>
@import
'@/assets/css/custom.scss'
;
.container
{
margin
:
0
auto
;
min-height
:
100vh
;
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
text-align
:
center
;
}
</
style
>
store/index.js
View file @
a417a8d8
...
...
@@ -9,6 +9,9 @@ const createStore = () => {
setToken
(
state
,
token
)
{
state
.
token
=
token
},
clearToken
(
state
)
{
stateate
.
token
=
null
},
},
actions
:
{
authenticationUser
(
context
,
credentials
)
{
...
...
@@ -29,6 +32,10 @@ const createStore = () => {
alert
(
'Register Success !'
)
}
else
{
alert
(
'Login Success !'
)
// console.log(result)
context
.
commit
(
'setToken'
,
result
.
idToken
)
// context.commit('setToken', result.idToken)
this
.
$router
.
push
(
'my_page'
)
}
// window.location.href = '/'
})
...
...
@@ -36,6 +43,16 @@ const createStore = () => {
alert
(
e
)
})
},
setLogoutTinme
(
context
,
duration
)
{
setTimeout
(()
=>
{
contextontext
.
commit
(
'clearToken'
)
},
duration
)
},
},
getters
:
{
isAuth
(
state
)
{
return
state
.
token
!=
null
},
},
})
}
...
...
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