File size: 1,084 Bytes
52b4c36
3ba9c0c
52b4c36
 
3ba9c0c
52b4c36
c69ef3e
 
3ba9c0c
 
f80b091
3ba9c0c
 
b841f1a
f80b091
b841f1a
f80b091
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ba9c0c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use client';

import * as React from 'react';
import { signIn } from 'next-auth/react';

import { cn } from '@/lib/utils';
import { Button, type ButtonProps } from '@/components/ui/Button';
import { IconGitHub, IconSpinner, IconGoogle } from '@/components/ui/Icons';

interface LoginButtonProps extends ButtonProps {
  oauth: 'github' | 'google';
}

export function LoginButton({ oauth, ...props }: LoginButtonProps) {
  const [isLoading, setIsLoading] = React.useState(false);

  const icon =
    oauth === 'github' ? (
      <IconGitHub className="mr-2" />
    ) : (
      <IconGoogle className="mr-2" />
    );
  return (
    <Button
      variant="outline"
      onClick={() => {
        setIsLoading(true);
        // next-auth signIn() function doesn't work yet at Edge Runtime due to usage of BroadcastChannel
        signIn(oauth, { callbackUrl: `/` });
      }}
      disabled={isLoading}
      {...props}
    >
      {isLoading ? <IconSpinner className="mr-2 animate-spin" /> : icon}
      Sign in with {oauth.charAt(0).toUpperCase() + oauth.slice(1)}
    </Button>
  );
}