import { GoogleLogo, Icon } from '@phosphor-icons/react'; import { Apple, Github } from '@sd/assets/svgs/brands'; import { RSPCError } from '@spacedrive/rspc-client'; import { UseMutationResult } from '@tanstack/react-query'; import { open } from '@tauri-apps/plugin-shell'; import clsx from 'clsx'; import { motion } from 'framer-motion'; import { Dispatch, SetStateAction, useState } from 'react'; import { getAuthorisationURLWithQueryParamsAndSetState } from 'supertokens-web-js/recipe/thirdparty'; import { Card, toast } from '@sd/ui'; import { Icon as Logo } from '~/components'; import { useIsDark } from '~/hooks'; import Login from './Login'; import Register from './Register'; export const AccountTabs = ['Login', 'Register'] as const; export type SocialLogin = { name: 'Github' | 'Google' | 'Apple'; icon: Icon; }; export const SocialLogins: SocialLogin[] = [ { name: 'Github', icon: Github }, { name: 'Google', icon: GoogleLogo }, { name: 'Apple', icon: Apple } ]; export const Authentication = ({ reload, cloudBootstrap }: { reload: Dispatch>; cloudBootstrap: UseMutationResult; // Cloud bootstrap mutation }) => { const [activeTab, setActiveTab] = useState<'Login' | 'Register'>('Login'); const isDark = useIsDark(); // Currently not in use due to backend issues - @Rocky43007 const socialLoginHandlers = (name: SocialLogin['name']) => { return { Github: async () => { try { const authUrl = await getAuthorisationURLWithQueryParamsAndSetState({ thirdPartyId: 'github', frontendRedirectURI: 'http://localhost:9420/api/auth/callback/github' }); await open(authUrl); } catch (err: any) { if (err.isSuperTokensGeneralError === true) { toast.error(err.message); } else { toast.error('Oops! Something went wrong.'); } } }, Google: async () => { try { const authUrl = await getAuthorisationURLWithQueryParamsAndSetState({ thirdPartyId: 'google', frontendRedirectURI: 'spacedrive://-/auth' }); await open(authUrl); } catch (err: any) { if (err.isSuperTokensGeneralError === true) { toast.error(err.message); } else { toast.error('Oops! Something went wrong.'); } } }, Apple: async () => { try { const authUrl = await getAuthorisationURLWithQueryParamsAndSetState({ thirdPartyId: 'apple', frontendRedirectURI: 'http://localhost:9420/api/auth/callback/apple' }); await open(authUrl); } catch (err: any) { if (err.isSuperTokensGeneralError === true) { toast.error(err.message); } else { toast.error('Oops! Something went wrong.'); } } } }[name](); }; return (
{AccountTabs.map((text) => (
setActiveTab(text)} className={clsx( 'relative flex-1 cursor-pointer border-b border-app-line p-3 text-center transition-colors duration-200', text === 'Login' ? 'rounded-tl-lg' : 'rounded-tr-lg', text === activeTab ? 'bg-app-background-alt' : '' )} >

{text}

{text === activeTab && ( )}
))}

Spacedrive Cloud

{activeTab === 'Login' ? ( ) : ( )}
Social auth and SSO (Single Sign On) available soon!
{/* Optionally, uncomment the social login block when ready */} {/*

OR

{SocialLogins.map((social) => ( ))}
*/}
); };