Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
aed7f643
Commit
aed7f643
authored
Feb 27, 2019
by
Samundra Shrestha
Committed by
Tim Neutkens
Feb 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add extra info to authentication (#6435)
* add extra info to authentication * Update auth.js
parent
806bfdfa
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
0 deletions
+6
-0
auth.js
examples/with-cookie-auth/www/utils/auth.js
+6
-0
No files found.
examples/with-cookie-auth/www/utils/auth.js
View file @
aed7f643
...
@@ -63,12 +63,18 @@ export const withAuthSync = WrappedComponent =>
...
@@ -63,12 +63,18 @@ export const withAuthSync = WrappedComponent =>
export
const
auth
=
ctx
=>
{
export
const
auth
=
ctx
=>
{
const
{
token
}
=
nextCookie
(
ctx
)
const
{
token
}
=
nextCookie
(
ctx
)
/*
* This happens on server only, ctx.req is available means it's being
* rendered on server. If we are on server and token is not available,
* means user is not logged in.
*/
if
(
ctx
.
req
&&
!
token
)
{
if
(
ctx
.
req
&&
!
token
)
{
ctx
.
res
.
writeHead
(
302
,
{
Location
:
'/login'
})
ctx
.
res
.
writeHead
(
302
,
{
Location
:
'/login'
})
ctx
.
res
.
end
()
ctx
.
res
.
end
()
return
return
}
}
// We already checked for server. This should only happen on client.
if
(
!
token
)
{
if
(
!
token
)
{
Router
.
push
(
'/login'
)
Router
.
push
(
'/login'
)
}
}
...
...
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