-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make all features in webserver requires auth (#992)
* feat: require auth for webserver features * cleanup frontend * feat: add flag --webserver * implement admin * update format
- Loading branch information
Showing
13 changed files
with
89 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,23 @@ | ||
import React from 'react' | ||
import Link from 'next/link' | ||
|
||
import { | ||
useAuthenticatedSession, | ||
useIsAdminInitialized, | ||
useSession, | ||
useSignOut | ||
} from '@/lib/tabby/auth' | ||
import { cn } from '@/lib/utils' | ||
import { useAuthenticatedSession, useSignOut } from '@/lib/tabby/auth' | ||
|
||
import { IconLogout, IconUnlock } from './ui/icons' | ||
import { IconLogout } from './ui/icons' | ||
|
||
export default function UserPanel() { | ||
const isAdminInitialized = useIsAdminInitialized() | ||
|
||
const Component = isAdminInitialized ? UserInfoPanel : EnableAdminPanel | ||
|
||
return ( | ||
<div className="py-4 flex justify-center text-sm font-medium"> | ||
<Component className={cn('flex items-center gap-2')} /> | ||
</div> | ||
) | ||
} | ||
|
||
function UserInfoPanel({ className }: React.ComponentProps<'span'>) { | ||
const session = useAuthenticatedSession() | ||
const signOut = useSignOut() | ||
|
||
return ( | ||
session && ( | ||
<span className={className}> | ||
<span title="Sign out"> | ||
<IconLogout className="cursor-pointer" onClick={signOut} /> | ||
<div className="py-4 flex justify-center text-sm font-medium"> | ||
<span className="flex items-center gap-2"> | ||
<span title="Sign out"> | ||
<IconLogout className="cursor-pointer" onClick={signOut} /> | ||
</span> | ||
{session.email} | ||
</span> | ||
{session.email} | ||
</span> | ||
</div> | ||
) | ||
) | ||
} | ||
|
||
function EnableAdminPanel({ className }: React.ComponentProps<'span'>) { | ||
return ( | ||
<Link | ||
className={cn('cursor-pointer', className)} | ||
title="Authentication is currently not enabled. Click to view details" | ||
href={{ | ||
pathname: '/auth/signup', | ||
query: { isAdmin: true } | ||
}} | ||
> | ||
<IconUnlock /> Secure Access | ||
</Link> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
export default function tokenFetcher([url, token]: Array< | ||
string | undefined | ||
>): Promise<any> { | ||
export default function tokenFetcher([url, token]: [ | ||
string, | ||
string | ||
]): Promise<any> { | ||
const headers = new Headers() | ||
if (token) { | ||
headers.append('authorization', `Bearer ${token}`) | ||
} | ||
headers.append('authorization', `Bearer ${token}`) | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
url = `${process.env.NEXT_PUBLIC_TABBY_SERVER_URL}${url}` | ||
} | ||
|
||
return fetch(url!, { headers }).then(x => x.json()) | ||
return fetch(url, { headers }).then(x => x.json()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters