mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 18:30:15 +01:00
feat: facebook login (#820)
* Facebook strategy * Update user_auth_system.md * Update user_auth_system.md
This commit is contained in:
parent
a569020312
commit
007d51ede1
23 changed files with 155 additions and 27 deletions
|
|
@ -4,7 +4,7 @@ import { useAuthContext } from '~/hooks/AuthContext';
|
|||
import { useNavigate } from 'react-router-dom';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { useGetStartupConfig } from 'librechat-data-provider';
|
||||
import { GoogleIcon, OpenIDIcon, GithubIcon, DiscordIcon } from '~/components';
|
||||
import { GoogleIcon, FacebookIcon, OpenIDIcon, GithubIcon, DiscordIcon } from '~/components';
|
||||
|
||||
function Login() {
|
||||
const { login, error, isAuthenticated } = useAuthContext();
|
||||
|
|
@ -65,6 +65,20 @@ function Login() {
|
|||
</div>
|
||||
</>
|
||||
)}
|
||||
{startupConfig?.facebookLoginEnabled && startupConfig?.socialLoginEnabled && (
|
||||
<>
|
||||
<div className="mt-2 flex gap-x-2">
|
||||
<a
|
||||
aria-label="Login with Facebook"
|
||||
className="justify-left flex w-full items-center space-x-3 rounded-md border border-gray-300 px-5 py-3 hover:bg-gray-50 focus:ring-2 focus:ring-violet-600 focus:ring-offset-1"
|
||||
href={`${startupConfig.serverDomain}/oauth/facebook`}
|
||||
>
|
||||
<FacebookIcon />
|
||||
<p>{localize('com_auth_facebook_login')}</p>
|
||||
</a>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{startupConfig?.openidLoginEnabled && startupConfig?.socialLoginEnabled && (
|
||||
<>
|
||||
<div className="mt-2 flex gap-x-2">
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import {
|
|||
TRegisterUser,
|
||||
useGetStartupConfig,
|
||||
} from 'librechat-data-provider';
|
||||
import { GoogleIcon, OpenIDIcon, GithubIcon, DiscordIcon } from '~/components';
|
||||
import { GoogleIcon, FacebookIcon, OpenIDIcon, GithubIcon, DiscordIcon } from '~/components';
|
||||
|
||||
function Registration() {
|
||||
const navigate = useNavigate();
|
||||
|
|
@ -308,6 +308,20 @@ function Registration() {
|
|||
</div>
|
||||
</>
|
||||
)}
|
||||
{startupConfig?.facebookLoginEnabled && startupConfig?.socialLoginEnabled && (
|
||||
<>
|
||||
<div className="mt-2 flex gap-x-2">
|
||||
<a
|
||||
aria-label="Login with Facebook"
|
||||
className="justify-left flex w-full items-center space-x-3 rounded-md border border-gray-300 px-5 py-3 hover:bg-gray-50 focus:ring-2 focus:ring-violet-600 focus:ring-offset-1"
|
||||
href={`${startupConfig.serverDomain}/oauth/facebook`}
|
||||
>
|
||||
<FacebookIcon />
|
||||
<p>{localize('com_auth_facebook_login')}</p>
|
||||
</a>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{startupConfig?.openidLoginEnabled && startupConfig?.socialLoginEnabled && (
|
||||
<>
|
||||
<div className="mt-2 flex gap-x-2">
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ const setup = ({
|
|||
isError: false,
|
||||
data: {
|
||||
googleLoginEnabled: true,
|
||||
facebookLoginEnabled: true,
|
||||
openidLoginEnabled: true,
|
||||
openidLabel: 'Test OpenID',
|
||||
openidImageUrl: 'http://test-server.com',
|
||||
|
|
@ -67,6 +68,21 @@ test('renders login form', () => {
|
|||
'href',
|
||||
'mock-server/oauth/google',
|
||||
);
|
||||
expect(getByRole('link', { name: /Login with Facebook/i })).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: /Login with Facebook/i })).toHaveAttribute(
|
||||
'href',
|
||||
'mock-server/oauth/facebook',
|
||||
);
|
||||
expect(getByRole('link', { name: /Login with Github/i })).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: /Login with Github/i })).toHaveAttribute(
|
||||
'href',
|
||||
'mock-server/oauth/github',
|
||||
);
|
||||
expect(getByRole('link', { name: /Login with Discord/i })).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: /Login with Discord/i })).toHaveAttribute(
|
||||
'href',
|
||||
'mock-server/oauth/discord',
|
||||
);
|
||||
});
|
||||
|
||||
test('calls loginUser.mutate on login', async () => {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ const setup = ({
|
|||
isError: false,
|
||||
data: {
|
||||
googleLoginEnabled: true,
|
||||
facebookLoginEnabled: true,
|
||||
openidLoginEnabled: true,
|
||||
openidLabel: 'Test OpenID',
|
||||
openidImageUrl: 'http://test-server.com',
|
||||
|
|
@ -75,6 +76,21 @@ test('renders registration form', () => {
|
|||
'href',
|
||||
'mock-server/oauth/google',
|
||||
);
|
||||
expect(getByRole('link', { name: /Login with Facebook/i })).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: /Login with Facebook/i })).toHaveAttribute(
|
||||
'href',
|
||||
'mock-server/oauth/facebook',
|
||||
);
|
||||
expect(getByRole('link', { name: /Login with Github/i })).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: /Login with Github/i })).toHaveAttribute(
|
||||
'href',
|
||||
'mock-server/oauth/github',
|
||||
);
|
||||
expect(getByRole('link', { name: /Login with Discord/i })).toBeInTheDocument();
|
||||
expect(getByRole('link', { name: /Login with Discord/i })).toHaveAttribute(
|
||||
'href',
|
||||
'mock-server/oauth/discord',
|
||||
);
|
||||
});
|
||||
|
||||
// eslint-disable-next-line jest/no-commented-out-tests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue