Skip to content

Commit 04ba7f2

Browse files
committed
Show sign in button when logged out on profile. SDK readme links to profile api-keys page
1 parent e56acf0 commit 04ba7f2

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

sdk/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ npm install @codebuff/sdk
1010

1111
## Prerequisites
1212

13-
1. Create a [Codebuff account](https://codebuff.com)
14-
2. Get your [Codebuff API key](https://www.codebuff.com/profile?tab=api-keys)
13+
Create a Codebuff account and get your [Codebuff API key here](https://www.codebuff.com/profile?tab=api-keys).
1514

1615
## Usage
1716

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use client'
2+
3+
import {
4+
Card,
5+
CardContent,
6+
CardDescription,
7+
CardHeader,
8+
CardTitle,
9+
} from '@/components/ui/card'
10+
import { SignInButton } from '@/components/sign-in/sign-in-button'
11+
12+
export function ProfileLoggedOut() {
13+
return (
14+
<div className="container mx-auto px-4 py-8">
15+
<div className="flex justify-center">
16+
<Card className="w-full max-w-2xl bg-gradient-to-br from-background via-background to-accent/5 border-border/50 shadow-lg">
17+
<CardHeader className="text-center pb-6">
18+
<CardTitle className="text-3xl font-bold mb-4">
19+
Sign in to Codebuff
20+
</CardTitle>
21+
<CardDescription className="text-lg text-muted-foreground">
22+
Access your account settings and manage your profile
23+
</CardDescription>
24+
</CardHeader>
25+
<CardContent className="flex justify-center py-8">
26+
<SignInButton providerName="github" providerDomain="github.com" />
27+
</CardContent>
28+
</Card>
29+
</div>
30+
</div>
31+
)
32+
}

web/src/app/profile/page.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useState, useEffect } from 'react'
44
import { useSearchParams } from 'next/navigation'
5+
import { useSession } from 'next-auth/react'
56
import { CreditCard, Shield, Users, Key, Menu } from 'lucide-react'
67
import { cn } from '@/lib/utils'
78

@@ -10,8 +11,10 @@ import { SecuritySection } from './components/security-section'
1011
import { ReferralsSection } from './components/referrals-section'
1112
import { UsageSection } from './components/usage-section'
1213
import { ApiKeysSection } from './components/api-keys-section'
14+
import { ProfileLoggedOut } from './components/logged-out'
1315
import { Button } from '@/components/ui/button'
1416
import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'
17+
import { Skeleton } from '@/components/ui/skeleton'
1518

1619
const sections = [
1720
{
@@ -75,6 +78,7 @@ function ProfileSidebar({
7578
}
7679

7780
export default function ProfilePage() {
81+
const { status } = useSession()
7882
const searchParams = useSearchParams()
7983
const [activeSection, setActiveSection] = useState('usage')
8084
const [open, setOpen] = useState(false)
@@ -99,6 +103,27 @@ export default function ProfilePage() {
99103
window.history.replaceState({}, '', url.toString())
100104
}
101105

106+
// Loading state
107+
if (status === 'loading') {
108+
return (
109+
<div className="container mx-auto px-4 py-8">
110+
<div className="flex justify-center">
111+
<div className="w-full max-w-2xl space-y-4">
112+
<Skeleton className="h-8 w-64" />
113+
<Skeleton className="h-4 w-96" />
114+
<Skeleton className="h-64 w-full" />
115+
</div>
116+
</div>
117+
</div>
118+
)
119+
}
120+
121+
// Unauthenticated state
122+
if (status === 'unauthenticated') {
123+
return <ProfileLoggedOut />
124+
}
125+
126+
// Authenticated state - render normal profile content
102127
return (
103128
<div className="container mx-auto px-4 py-8">
104129
<div className="flex gap-8">

web/src/components/sign-in/sign-in-button.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,24 @@ import { Button } from '@/components/ui/button'
1616
export const SignInButton = ({
1717
providerName,
1818
providerDomain,
19+
onClick, // Additional handler for analytics/tracking
1920
}: {
2021
providerName: OAuthProviderType
2122
providerDomain: string
23+
onClick?: () => void
2224
}) => {
2325
const [isPending, startTransition] = useTransition()
2426
const pathname = usePathname()
2527
const searchParams = useSearchParams()
2628

2729
const handleSignIn = () => {
30+
onClick?.()
31+
2832
startTransition(async () => {
29-
let callbackUrl = pathname
33+
// Include search params in callback URL to preserve context
34+
const searchParamsString = searchParams.toString()
35+
let callbackUrl =
36+
pathname + (searchParamsString ? `?${searchParamsString}` : '')
3037

3138
if (pathname === '/login') {
3239
const authCode = searchParams.get('auth_code')
@@ -42,6 +49,12 @@ export const SignInButton = ({
4249
}
4350
callbackUrl = '/'
4451
}
52+
} else {
53+
// For non-login pages, store referral_code if present
54+
const referralCode = searchParams.get('referral_code')
55+
if (referralCode) {
56+
localStorage.setItem('referral_code', referralCode)
57+
}
4558
}
4659

4760
posthog.capture('auth.login_started', {

0 commit comments

Comments
 (0)