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

Skip to content

Commit 259094c

Browse files
committed
Add login with LinkedIn in dev environment
1 parent 357b6a3 commit 259094c

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

src/components/HomePageFeed.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,11 @@ export default function HomePageFeed({
225225
}) {
226226
const [session] = useSession()
227227
return (
228-
<div className="min-h-screen bg-gray-100">
228+
<div className="min-h-screen bg-gray-100 flex flex-col">
229229
<header className="bg-white shadow-sm lg:static lg:overflow-y-visible">
230230
<AppNavBar />
231231
</header>
232-
233-
<div className="py-10">
232+
<div className="py-10 flex-1">
234233
<div className="max-w-3xl mx-auto sm:px-6 lg:max-w-7xl lg:px-8 lg:grid lg:grid-cols-12 lg:gap-8">
235234
<div className="hidden lg:block lg:col-span-3 xl:col-span-2">
236235
<HomePageSideNavBar />

src/pages/api/auth/[...nextauth].ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Fauna from '@/adapters'
55

66
import faunadb from 'faunadb'
77
import { User } from 'src/pages/members'
8+
import slugify from 'slugify'
89
const isProduction = process.env.NODE_ENV === 'production'
910
const faunaClient = new faunadb.Client({
1011
secret: process.env.FAUNADB_SECRET ?? 'secret',
@@ -33,6 +34,45 @@ const options: InitOptions = {
3334
}
3435
},
3536
}),
37+
...(isProduction
38+
? []
39+
: [
40+
Providers.LinkedIn({
41+
clientId: process.env.LINKEDIN_ID,
42+
clientSecret: process.env.LINKEDIN_SECRET,
43+
scope: 'r_liteprofile',
44+
// @ts-ignore
45+
profileUrl:
46+
'https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName,profilePicture(displayImage~digitalmediaAsset:playableStreams))',
47+
// @ts-ignore
48+
profile: (profileData) => {
49+
const profileImage =
50+
profileData?.profilePicture?.['displayImage~']?.elements?.[3]
51+
?.identifiers?.[0]?.identifier ??
52+
profileData?.profilePicture?.['displayImage~']?.elements?.[2]
53+
?.identifiers?.[0]?.identifier ??
54+
profileData?.profilePicture?.['displayImage~']?.elements?.[1]
55+
?.identifiers?.[0]?.identifier ??
56+
profileData?.profilePicture?.['displayImage~']?.elements?.[0]
57+
?.identifiers?.[0]?.identifier ??
58+
''
59+
const name =
60+
profileData.localizedFirstName +
61+
' ' +
62+
profileData.localizedLastName
63+
const username = slugify(name + ' ' + profileData.id, {
64+
lower: true,
65+
})
66+
return {
67+
id: profileData.id,
68+
name,
69+
email: null,
70+
image: profileImage,
71+
username,
72+
}
73+
},
74+
}),
75+
]),
3676
],
3777
adapter: Fauna.Adapter({ faunaClient }),
3878

src/pages/join.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Button } from '@/ui'
2-
import { IconBrandGithub } from 'tabler-icons'
2+
import { IconBrandGithub, IconBrandLinkedin } from 'tabler-icons'
33
import { signIn, useSession } from 'next-auth/client'
44
import { GetServerSideProps } from 'next'
55
import { useEffect } from 'react'
@@ -8,6 +8,7 @@ import { Logo } from '@/components'
88

99
export default function Login({ callbackUrl }) {
1010
const router = useRouter()
11+
const isProduction = process.env.NODE_ENV === 'production'
1112
const [session, loading] = useSession()
1213

1314
useEffect(() => {
@@ -44,6 +45,19 @@ export default function Login({ callbackUrl }) {
4445
GitHub
4546
</Button>
4647
</div>
48+
{!isProduction && (
49+
<div className="grid grid-cols-1 gap-3 mt-6">
50+
<Button
51+
className="flex justify-center w-full"
52+
leadingIcon={IconBrandLinkedin}
53+
variant="solid"
54+
variantColor="brand"
55+
onClick={() => signIn('linkedin')}
56+
>
57+
LinkedIn
58+
</Button>
59+
</div>
60+
)}
4761
</div>
4862
</div>
4963
</div>

0 commit comments

Comments
 (0)