Skip to content

Commit

Permalink
Add user role to UserContext
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiuszbachorski committed Jul 21, 2024
1 parent bbe0c4b commit df4783d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 11 additions & 2 deletions app/(dashboard)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
// SPDX-License-Identifier: MIT
//
import { type ReactNode } from 'react'
import { getAuthenticatedOnlyApp } from '@/modules/firebase/guards'
import {
getAuthenticatedOnlyApp,
getCurrentUserRole,
} from '@/modules/firebase/guards'
import { UserContextProvider } from '@/modules/firebase/UserProvider'
import { getUserInfo } from '@/packages/design-system/src/modules/auth/user'

Expand All @@ -18,8 +21,14 @@ export const dynamic = 'force-dynamic'

const DashboardLayout = async ({ children }: DashboardLayoutProps) => {
const { currentUser } = await getAuthenticatedOnlyApp()
const { role } = await getCurrentUserRole()
return (
<UserContextProvider user={getUserInfo(currentUser)}>
<UserContextProvider
user={{
...getUserInfo(currentUser),
role,
}}
>
{children}
</UserContextProvider>
)
Expand Down
7 changes: 5 additions & 2 deletions modules/firebase/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
'use client'
import { type UserInfo } from '@firebase/auth-types'
import { createContext, type ReactNode, useContext } from 'react'
import { type Role } from '@/modules/firebase/role'

export const UserContext = createContext<UserInfo | undefined>(undefined)
type Context = UserInfo & { role: Role }

export const UserContext = createContext<Context | undefined>(undefined)

interface UserContextProviderProps {
children?: ReactNode
user: UserInfo
user: Context
}

export const UserContextProvider = ({
Expand Down

0 comments on commit df4783d

Please sign in to comment.