( request: Request, )
| 67 | } |
| 68 | |
| 69 | export async function getDataFromRequest( |
| 70 | request: Request, |
| 71 | ): Promise<{ user: User; session: UserSession | undefined; tokenData?: JwtData['data'] } | null> { |
| 72 | try { |
| 73 | const cookies = getCookies(request.headers); |
| 74 | |
| 75 | if (cookies[COOKIE_NAME]) { |
| 76 | const result = await getDataFromCookie(cookies[COOKIE_NAME]); |
| 77 | |
| 78 | if (result) { |
| 79 | return result; |
| 80 | } |
| 81 | } |
| 82 | } catch (error) { |
| 83 | // Don't crash on potentially-troublesome Cookie headers (https://github.com/bewcloud/bewcloud/issues/162) |
| 84 | console.error(error); |
| 85 | } |
| 86 | |
| 87 | const authorizationHeader = request.headers.get('authorization'); |
| 88 | |
| 89 | if (authorizationHeader) { |
| 90 | const result = await getDataFromAuthorizationHeader(authorizationHeader); |
| 91 | |
| 92 | if (result) { |
| 93 | return result; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return null; |
| 98 | } |
| 99 | |
| 100 | async function getDataFromAuthorizationHeader(authorizationHeader: string) { |
| 101 | if (!authorizationHeader) { |
no test coverage detected