-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
212 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,79 @@ | ||
*, :after, :before { | ||
box-sizing: border-box; | ||
*, | ||
:after, | ||
:before { | ||
box-sizing: border-box; | ||
} | ||
|
||
a { | ||
text-decoration: none !important; | ||
cursor: pointer; | ||
color: #0070f3; | ||
text-decoration: none !important; | ||
cursor: pointer; | ||
color: #0070f3; | ||
} | ||
|
||
a:hover { | ||
color: #0366d6; | ||
color: #0366d6; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
padding: 0; | ||
color: #111; | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
color: #111; | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', | ||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', | ||
sans-serif; | ||
} | ||
|
||
main { | ||
padding: 1rem; | ||
max-width: 1040px; | ||
margin: 0 auto; | ||
padding: 1rem; | ||
max-width: 1040px; | ||
margin: 0 auto; | ||
} | ||
|
||
label { | ||
display: flex; | ||
margin-bottom: 0.5rem; | ||
align-items: center; | ||
width: 100%; | ||
display: flex; | ||
margin-bottom: 0.5rem; | ||
align-items: center; | ||
width: 100%; | ||
} | ||
|
||
form { | ||
margin-bottom: 0.5rem; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
margin-bottom: 0.5rem; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
input, | ||
textarea { | ||
font-family: monospace; | ||
flex: 1 1 0%; | ||
margin-left: 0.5rem; | ||
box-shadow: none; | ||
width: 100%; | ||
color: #000; | ||
background-color: transparent; | ||
border: 1px solid #d8d8d8; | ||
border-radius: 5px; | ||
outline: 0px; | ||
padding: 10px 25px; | ||
font-family: monospace; | ||
flex: 1 1 0%; | ||
margin-left: 0.5rem; | ||
box-shadow: none; | ||
width: 100%; | ||
color: #000; | ||
background-color: transparent; | ||
border: 1px solid #d8d8d8; | ||
border-radius: 5px; | ||
outline: 0px; | ||
padding: 10px 25px; | ||
} | ||
|
||
button { | ||
display: block; | ||
margin-bottom: 0.5rem; | ||
color: #fff; | ||
border-radius: 5px; | ||
border: none; | ||
background-color: #000; | ||
cursor: pointer; | ||
transition: all 0.2s ease 0s; | ||
padding: 10px 25px; | ||
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.12); | ||
display: block; | ||
margin-bottom: 0.5rem; | ||
color: #fff; | ||
border-radius: 5px; | ||
border: none; | ||
background-color: #000; | ||
cursor: pointer; | ||
transition: all 0.2s ease 0s; | ||
padding: 10px 25px; | ||
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.12); | ||
} | ||
|
||
button:hover, | ||
button:active { | ||
transform: translate3d(0px, -1px, 0px); | ||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12); | ||
} | ||
transform: translate3d(0px, -1px, 0px); | ||
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import useSWR from 'swr'; | ||
import useSWR from 'swr' | ||
|
||
const fetcher = (url) => fetch(url).then((r) => r.json()); | ||
const fetcher = (url) => fetch(url).then((r) => r.json()) | ||
|
||
export function usePost() { | ||
const { data, mutate } = useSWR('/api/posts', fetcher); | ||
const posts = data?.posts; | ||
return [posts, { mutate }]; | ||
const { data, mutate } = useSWR('/api/posts', fetcher) | ||
const posts = data?.posts | ||
return [posts, { mutate }] | ||
} | ||
|
||
export function useUser() { | ||
const { data, mutate } = useSWR('/api/user', fetcher); | ||
const user = data?.user; | ||
return [user, { mutate }]; | ||
const { data, mutate } = useSWR('/api/user', fetcher) | ||
const user = data?.user | ||
return [user, { mutate }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import passport from 'passport'; | ||
import LocalStrategy from 'passport-local'; | ||
import passport from 'passport' | ||
import LocalStrategy from 'passport-local' | ||
|
||
passport.serializeUser(function (user, done) { | ||
// In practice, we do not serialize the whole user object but just the id | ||
// done(null, user.id) | ||
done(null, user); | ||
}); | ||
done(null, user) | ||
}) | ||
|
||
passport.deserializeUser(function (id, done) { | ||
// In practice, id will just be an id. In this case, it is the whole user object as shown in passport.serializeUser | ||
// It is to used to query the database | ||
// db.findUserById(id).then((user) => { | ||
// done(null, user); | ||
// }); | ||
done(null, id); | ||
}); | ||
done(null, id) | ||
}) | ||
|
||
passport.use( | ||
new LocalStrategy((username, password, done) => { | ||
// Here you should lookup for the user in your DB and compare the password | ||
if (password === 'hackme') { | ||
// return the user if the password is correct | ||
done(null, { username }); | ||
done(null, { username }) | ||
} else { | ||
// return null if the password is incorrect | ||
done(null, null); | ||
done(null, null) | ||
} | ||
}) | ||
); | ||
) | ||
|
||
export default passport; | ||
export default passport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import Layout from '../components/Layout'; | ||
import Layout from '../components/Layout' | ||
import '../assets/style.css' | ||
|
||
export default function MyApp({ Component, pageProps }) { | ||
return ( | ||
<Layout> | ||
<Component {...pageProps} /> | ||
</Layout> | ||
); | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import nextConnect from 'next-connect'; | ||
import auth from '../../middleware/auth'; | ||
import passport from '../../lib/passport'; | ||
import nextConnect from 'next-connect' | ||
import auth from '../../middleware/auth' | ||
import passport from '../../lib/passport' | ||
|
||
const handler = nextConnect(); | ||
const handler = nextConnect() | ||
|
||
handler.use(auth).post(passport.authenticate('local'), (req, res) => { | ||
if (req.user) { | ||
// For demo purpose only. See pages/api/posts/ | ||
req.session.posts = []; | ||
req.session.posts = [] | ||
} | ||
res.json({ user: req.user }); | ||
}); | ||
res.json({ user: req.user }) | ||
}) | ||
|
||
export default handler; | ||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import nextConnect from 'next-connect'; | ||
import auth from '../../middleware/auth'; | ||
import nextConnect from 'next-connect' | ||
import auth from '../../middleware/auth' | ||
|
||
const handler = nextConnect(); | ||
const handler = nextConnect() | ||
|
||
handler.use(auth).get((req, res) => { | ||
req.logOut(); | ||
res.status(204).end(); | ||
}); | ||
req.logOut() | ||
res.status(204).end() | ||
}) | ||
|
||
export default handler; | ||
export default handler |
Oops, something went wrong.