Skip to content

Commit 904c913

Browse files
committed
feat: add user supporter status to authentication flow and update Card component logic
1 parent 5be1db7 commit 904c913

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/components/Elements/Card/Card.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import clsx from 'clsx'
22
import React, { useEffect, useState } from 'react'
33
import { AdvBanner } from 'src/features/adv'
4+
import { useAuth } from 'src/features/auth'
45
import { DesktopBreakpoint } from 'src/providers/DesktopBreakpoint'
56
import { MobileBreakpoint } from 'src/providers/MobileBreakpoint'
67
import { CardPropsType } from 'src/types'
@@ -27,6 +28,7 @@ export const Card = React.forwardRef<HTMLDivElement, RootCardProps>(
2728
) => {
2829
const { icon, label, badge } = meta
2930
const [canAdsLoad, setCanAdsLoad] = useState(true)
31+
const { user } = useAuth()
3032

3133
useEffect(() => {
3234
if (!withAds) {
@@ -65,7 +67,7 @@ export const Card = React.forwardRef<HTMLDivElement, RootCardProps>(
6567
{badge && <span className="blockHeaderBadge">{badge}</span>}
6668
</div>
6769

68-
{canAdsLoad && withAds && (
70+
{canAdsLoad && withAds && !user?.isSupporter && (
6971
<div className="ad-wrapper blockRow">
7072
<AdvBanner />
7173
</div>

src/features/auth/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export type User = {
44
connectedAt?: string
55
imageURL?: string
66
streak?: number
7+
isSupporter?: boolean
78
}

src/providers/AuthProvider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,19 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
3838
: GithubAuthProvider.credential(token)
3939

4040
return signInWithCredential(firebaseAuth, authProvider)
41-
.then((userCredential) => {
41+
.then(async (userCredential) => {
4242
const user = userCredential.user
4343

44+
const idToken = await user.getIdTokenResult()
45+
const isSupporter = Boolean(idToken.claims?.['supporter'])
46+
4447
initState({
4548
user: {
4649
id: user.uid,
4750
connectedAt: new Date().toISOString(),
4851
name: user.displayName || 'Anonymous',
4952
imageURL: user.photoURL || '',
53+
isSupporter: isSupporter,
5054
},
5155
providerId: authProvider.providerId,
5256
})

0 commit comments

Comments
 (0)