import { useUser, fetcher } from '../lib/hooks'
import useSWR from 'swr'
function UserList() {
const { data: { users } = {} } = useSWR('/api/users', fetcher)
return (
<>
All users
{!!users?.length && (
)}
>
)
}
export default function HomePage() {
const [user] = useUser()
return (
<>
Steps to test the example:
Sign up
- Click Sign up and enter a username and password.
- You will be logged in and redirected home.
- Click Logout. You will be redirected home.
-
Try sign up again with the same username, you will see an error.
Sign in
- Click Login and login again using the same credential.
- You will see an error if you use incorrect credential.
- Otherwise, you will be authenticated and redirected home.
Edit profile
- Click Profile
- Enter a new name and click Update profile.
- Notice how the name in Your profile has changed.
- Click Delete profile
-
The user is removed and is no longer shown in All users section in
Home
{user && (
<>
Currently logged in as:
{JSON.stringify(user, null, 2)}
>
)}
>
)
}