({ request }: LoaderFunctionArgs)
| 78 | } |
| 79 | |
| 80 | export async function loader({ request }: LoaderFunctionArgs) { |
| 81 | const timings = makeTimings('root loader') |
| 82 | const userId = await time(() => getUserId(request), { |
| 83 | timings, |
| 84 | type: 'getUserId', |
| 85 | desc: 'getUserId in root', |
| 86 | }) |
| 87 | |
| 88 | const user = userId |
| 89 | ? await time( |
| 90 | () => |
| 91 | prisma.user.findUniqueOrThrow({ |
| 92 | select: { |
| 93 | id: true, |
| 94 | name: true, |
| 95 | username: true, |
| 96 | image: { select: { id: true } }, |
| 97 | roles: { |
| 98 | select: { |
| 99 | name: true, |
| 100 | permissions: { |
| 101 | select: { entity: true, action: true, access: true }, |
| 102 | }, |
| 103 | }, |
| 104 | }, |
| 105 | }, |
| 106 | where: { id: userId }, |
| 107 | }), |
| 108 | { timings, type: 'find user', desc: 'find user in root' }, |
| 109 | ) |
| 110 | : null |
| 111 | if (userId && !user) { |
| 112 | console.info('something weird happened') |
| 113 | // something weird happened... The user is authenticated but we can't find |
| 114 | // them in the database. Maybe they were deleted? Let's log them out. |
| 115 | await logout({ request, redirectTo: '/' }) |
| 116 | } |
| 117 | const { toast, headers: toastHeaders } = await getToast(request) |
| 118 | const honeyProps = honeypot.getInputProps() |
| 119 | |
| 120 | return json( |
| 121 | { |
| 122 | user, |
| 123 | requestInfo: { |
| 124 | hints: getHints(request), |
| 125 | origin: getDomainUrl(request), |
| 126 | path: new URL(request.url).pathname, |
| 127 | userPrefs: { |
| 128 | theme: getTheme(request), |
| 129 | }, |
| 130 | }, |
| 131 | ENV: getEnv(), |
| 132 | toast, |
| 133 | honeyProps, |
| 134 | }, |
| 135 | { |
| 136 | headers: combineHeaders( |
| 137 | { 'Server-Timing': timings.toString() }, |
nothing calls this directly
no test coverage detected