Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5527681

Browse files
committed
Directly sign in users from navbar
1 parent f17492b commit 5527681

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

src/components/AppNavBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default function AppNavBar() {
101101
<Button
102102
variant="solid"
103103
variantColor="brand"
104-
onClick={() => signIn()}
104+
onClick={() => signIn('github')}
105105
>
106106
Join
107107
</Button>

src/components/HomePageFeed.tsx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Markdown, A } from '@/components'
1414
import { useMutation, useQuery } from 'react-query'
1515
import classNames from 'classnames'
1616
import { useEffect, useReducer, useState } from 'react'
17-
import { useSession } from 'next-auth/client'
17+
import { signIn, useSession } from 'next-auth/client'
1818
import {
1919
NewComment,
2020
NewUpdate,
@@ -311,14 +311,14 @@ function HomePageSideNavBar() {
311311
)}
312312
{!session && (
313313
<>
314-
<A
315-
href="/join"
314+
<button
315+
onClick={() => signIn('github')}
316316
className="text-gray-600 hover:bg-gray-50 group flex items-center px-3 py-2 text-sm font-medium rounded-md"
317317
aria-current="false"
318318
>
319319
<RocketLaunch className="text-gray-400 group-hover:text-gray-500 flex-shrink-0 -ml-1 mr-3 h-6 w-6" />
320320
<span className="truncate">Get Started</span>
321-
</A>
321+
</button>
322322
<A
323323
href="/members"
324324
className="text-gray-600 hover:bg-gray-50 group flex items-center px-3 py-2 text-sm font-medium rounded-md"
@@ -336,6 +336,7 @@ function HomePageSideNavBar() {
336336
}
337337

338338
function FollowButton({ user }: { user: User }) {
339+
const [session] = useSession()
339340
const { toggleFollow } = useFollowUser(user.id)
340341
const [isFollowing, setIsFollowing] = useState(false)
341342
return (
@@ -358,6 +359,10 @@ function FollowButton({ user }: { user: User }) {
358359
type="button"
359360
className="inline-flex items-center px-3 py-0.5 rounded-full bg-brand-50 text-sm font-medium text-brand-700 hover:bg-brand-100"
360361
onClick={() => {
362+
if (!session) {
363+
signIn('github')
364+
return
365+
}
361366
setIsFollowing(true)
362367
toggleFollow()
363368
}}
@@ -453,12 +458,12 @@ function HomePageAside({ updates }: { updates: HomePageFeedUpdateType[] }) {
453458
</div>
454459
) : (
455460
<div className="mt-6">
456-
<A
457-
href="/join"
461+
<button
462+
onClick={() => signIn('github')}
458463
className="w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
459464
>
460465
Join
461-
</A>
466+
</button>
462467
</div>
463468
)}
464469
</div>
@@ -484,12 +489,21 @@ function HomePageAside({ updates }: { updates: HomePageFeedUpdateType[] }) {
484489
</ul>
485490
</div>
486491
<div className="mt-6">
487-
<A
488-
href="/members"
489-
className="w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
490-
>
491-
View all
492-
</A>
492+
{session ? (
493+
<A
494+
href="/members"
495+
className="w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
496+
>
497+
View all
498+
</A>
499+
) : (
500+
<button
501+
onClick={() => signIn('github')}
502+
className="w-full block text-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
503+
>
504+
Join
505+
</button>
506+
)}
493507
</div>
494508
</div>
495509
</div>

src/pages/api/fauna/who-to-follow.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,28 @@ const FaunaCreateHandler: NextApiHandler = async (
4141
const session = await getSession({ req })
4242

4343
if (!session) {
44-
return res.status(200).json({ users: [] })
44+
const response: any = await client.query(
45+
q.Map(
46+
q.Paginate(q.Documents(q.Collection('users')), { size: 3 }),
47+
(userRef) => {
48+
const userDoc = q.Get(userRef)
49+
return {
50+
id: q.Select(['ref', 'id'], userDoc),
51+
name: q.Select(['data', 'name'], userDoc, null),
52+
image: q.Select(['data', 'image'], userDoc, null),
53+
username: q.Select(['data', 'username'], userDoc, null),
54+
account: {
55+
firstName: q.Select(
56+
['data', 'account', 'firstName'],
57+
userDoc,
58+
null
59+
),
60+
},
61+
}
62+
}
63+
)
64+
)
65+
return res.status(200).json({ users: response.data })
4566
}
4667

4768
const userId = (session.user as User).id

0 commit comments

Comments
 (0)