Skip to content

Commit

Permalink
feat(auth-client): Moved all components to components import path
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandarDev committed Oct 11, 2024
1 parent 67fa0a0 commit 949078d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions web/packages/auth-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Example imeplementation:
'use client';

import { PropsWithChildren } from 'react';
import { AuthProvider } from '@signalco/auth-client';
import { AuthProvider } from '@signalco/auth-client/components';

export type User = {
id: string;
Expand Down Expand Up @@ -57,7 +57,7 @@ const queryClient = new QueryClient();
Modes available for `AuthProtectedSection` are `hide` and `redirect`. Hide will hide the section if the user is not authenticated. Redirect will redirect the user to the specified URL.

```tsx
import { AuthProtectedSection } from '@signalco/auth-client';
import { AuthProtectedSection } from '@signalco/auth-client/components';

// This will hide the section if user is not authenticated
<AuthProtectedSection mode="hide">
Expand Down
4 changes: 2 additions & 2 deletions web/packages/auth-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@signalco/auth-client",
"version": "0.1.2",
"version": "0.2.0",
"license": "MIT",
"type": "module",
"sideEffects": false,
Expand Down Expand Up @@ -33,7 +33,6 @@
"@signalco/tailwindcss-config-signalco": "workspace:*",
"@signalco/tsconfig": "workspace:*",
"@signalco/ui-icons": "workspace:*",
"@signalco/ui-primitives": "workspace:*",
"@tanstack/react-query": "5.59.8",
"@types/react": "18.3.11",
"@types/react-dom": "18.3.0",
Expand All @@ -46,6 +45,7 @@
},
"peerDependencies": {
"@tanstack/react-query": ">=5",
"@signalco/ui-primitives": "0",
"next": ">=14",
"react": ">=18",
"react-dom": ">=18"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { PropsWithChildren } from 'react';
import { useRouter } from 'next/navigation';
import { useCurrentUser } from './useCurrentUser';
import { useCurrentUser } from '../useCurrentUser';

type AuthProtectedSectionProps = PropsWithChildren<{
mode?: 'hide';
Expand All @@ -24,5 +24,5 @@ export function AuthProtectedSection({ children, mode = 'hide', redirectUrl }: A
router.push(redirectUrl);
}

return children;
return <>{children}</>;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use client';

import { PropsWithChildren } from 'react';
import { AuthCurrentUserBase } from './useCurrentUser';
import { AuthContext, AuthContextValue } from './AuthContext';
import { AuthCurrentUserBase } from '../useCurrentUser';
import { AuthContext, AuthContextValue } from '../AuthContext';

export function AuthProvider<T extends AuthCurrentUserBase>({ children, ...rest }: PropsWithChildren & AuthContextValue<T>) {
return (
Expand Down
28 changes: 16 additions & 12 deletions web/packages/auth-client/src/components/UserButton.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
'use client';

import { useContext } from 'react';
import { Modal } from '@signalco/ui-primitives/Modal';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@signalco/ui-primitives/Menu';
import { IconButton } from '@signalco/ui-primitives/IconButton';
import { Button } from '@signalco/ui-primitives/Button';
import { Avatar } from '@signalco/ui-primitives/Avatar';
import { User } from '@signalco/ui-icons';
import { LogOut, User } from '@signalco/ui-icons';
import { AuthContext } from '../AuthContext';

export function UserButton() {
const authContext = useContext(AuthContext);
return (
<Modal trigger={(
<IconButton>
<Avatar>
<User />
</Avatar>
</IconButton>
)}>
<Button href={authContext.urls?.signOut ?? '/signout'}>Sign Out</Button>
</Modal>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton className="rounded-full">
<Avatar className="bg-transparent">
<User />
</Avatar>
</IconButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem href={authContext.urls?.signOut ?? '/sign-out'} startDecorator={<LogOut />}>
Sign out
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}
4 changes: 3 additions & 1 deletion web/packages/auth-client/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export * from './SignInButton';
export * from './SignUpButton';
export * from './SignedIn';
export * from './SignedOut';
export * from './UserButton';
export * from './UserButton';
export * from './AuthProtectedSection';
export * from './AuthProvider';
4 changes: 1 addition & 3 deletions web/packages/auth-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use client';

export * from './useCurrentUser';
export * from './AuthProtectedSection';
export * from './AuthProvider';
export * from './useCurrentUser';

0 comments on commit 949078d

Please sign in to comment.