Skip to content

Commit

Permalink
fix: non admin access to translation view
Browse files Browse the repository at this point in the history
  • Loading branch information
arrocke committed Oct 27, 2024
1 parent 5d155c1 commit 93acc5c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useSWRConfig } from "swr";

export interface TranslationToolbarProps {
languages: { name: string; code: string }[];
currentLanguage: { roles: string [] };
currentLanguage?: { roles: string [] };
}

export default function TranslationToolbar({
Expand All @@ -28,8 +28,8 @@ export default function TranslationToolbar({
const router = useRouter()
const { mutate } = useSWRConfig()

const isTranslator = currentLanguage.roles.includes('TRANSLATOR');
const isAdmin = currentLanguage.roles.includes('ADMIN');
const isTranslator = !!currentLanguage?.roles.includes('TRANSLATOR');
const isAdmin = !!currentLanguage?.roles.includes('ADMIN');

const { selectedWords, focusedPhrase, clearSelectedWords } = useTranslationClientState()
const canLinkWords = selectedWords.length > 1;
Expand Down
4 changes: 0 additions & 4 deletions app/[locale]/(authenticated)/translate/[code]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ export default async function InterlinearLayout({ children, params }: Props) {
if (!session) {
notFound()
}
const isAdmin = session.user.roles.includes('ADMIN')

const [languages, currentLanguage] = await Promise.all([
fetchLanguages(),
fetchCurrentLanguage(params.code, session?.user.id)
])
if (!currentLanguage || (!isAdmin && currentLanguage.roles.length === 0)) {
notFound()
}

return <div className={`absolute w-full h-full flex flex-col flex-grow`}>
<TranslationClientStateProvider>
Expand Down

0 comments on commit 93acc5c

Please sign in to comment.