Skip to content

Commit 3c77383

Browse files
authored
Merge pull request #67 from codeunia-dev/Oauth/github
Add GitHub OAuth sign-in functionality to SignInForm and SignUpForm
2 parents 65c52e7 + b90d351 commit 3c77383

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

app/auth/signin/page.tsx

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ function SignInForm() {
9191
}
9292
};
9393

94+
const handleGitHubSignIn = async () => {
95+
setIsLoading(true);
96+
try {
97+
const supabase = createClient();
98+
const { error } = await supabase.auth.signInWithOAuth({
99+
provider: 'github',
100+
options: {
101+
redirectTo: typeof window !== "undefined"
102+
? `${window.location.origin}/auth/callback?returnUrl=${encodeURIComponent(returnUrl)}`
103+
: undefined,
104+
},
105+
});
106+
if (error) {
107+
throw error;
108+
}
109+
toast.success("Redirecting to GitHub...");
110+
} catch (error) {
111+
console.error('GitHub sign in error:', error);
112+
toast.error("GitHub sign in failed. Please try again.");
113+
} finally {
114+
setIsLoading(false);
115+
}
116+
};
117+
94118
return (
95119
<div className="min-h-screen flex items-center justify-center py-12 px-4 bg-gradient-to-br from-background via-muted/30 to-muted/50 relative overflow-hidden">
96120

@@ -215,9 +239,20 @@ function SignInForm() {
215239
<Button
216240
variant="outline"
217241
className="w-full hover:bg-background/80 transition-colors backdrop-blur-sm border-white/10 hover:border-primary/20"
242+
onClick={handleGitHubSignIn}
243+
disabled={isLoading}
218244
>
219-
<Github className="mr-2 h-4 w-4" />
220-
GitHub
245+
{isLoading ? (
246+
<div className="flex items-center">
247+
<div className="animate-spin rounded-full h-4 w-4 border-2 border-primary border-t-transparent mr-2"></div>
248+
Connecting...
249+
</div>
250+
) : (
251+
<>
252+
<Github className="mr-2 h-4 w-4" />
253+
GitHub
254+
</>
255+
)}
221256
</Button>
222257
<Button
223258
variant="outline"

app/auth/signup/page.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ function SignUpForm() {
131131
}
132132
};
133133

134+
const handleGitHubSignIn = async () => {
135+
setIsLoading(true);
136+
try {
137+
const supabase = createClient();
138+
const { error } = await supabase.auth.signInWithOAuth({
139+
provider: 'github',
140+
options: {
141+
redirectTo: typeof window !== "undefined"
142+
? `${window.location.origin}/auth/callback?returnUrl=${encodeURIComponent(returnUrl)}`
143+
: undefined,
144+
},
145+
});
146+
if (error) {
147+
throw error;
148+
}
149+
toast.success("Redirecting to GitHub...");
150+
} catch (error) {
151+
console.error('GitHub sign in error:', error);
152+
toast.error("GitHub sign in failed. Please try again.");
153+
} finally {
154+
setIsLoading(false);
155+
}
156+
};
157+
134158
const passwordRequirements = [
135159
{ text: "At least 8 characters", met: formData.password.length >= 8 },
136160
{ text: "Contains uppercase letter", met: /[A-Z]/.test(formData.password) },
@@ -337,9 +361,23 @@ function SignUpForm() {
337361
<CardContent className="space-y-6 relative">
338362
{/* socials login */}
339363
<div className="grid grid-cols-2 gap-4">
340-
<Button variant="outline" className="w-full hover:bg-background/80 transition-colors backdrop-blur-sm border-white/10 hover:border-primary/20">
341-
<Github className="mr-2 h-4 w-4" />
342-
GitHub
364+
<Button
365+
variant="outline"
366+
className="w-full hover:bg-background/80 transition-colors backdrop-blur-sm border-white/10 hover:border-primary/20"
367+
onClick={handleGitHubSignIn}
368+
disabled={isLoading}
369+
>
370+
{isLoading ? (
371+
<div className="flex items-center">
372+
<div className="animate-spin rounded-full h-4 w-4 border-2 border-primary border-t-transparent mr-2"></div>
373+
Connecting...
374+
</div>
375+
) : (
376+
<>
377+
<Github className="mr-2 h-4 w-4" />
378+
GitHub
379+
</>
380+
)}
343381
</Button>
344382
<Button
345383
variant="outline"

0 commit comments

Comments
 (0)