forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
23 lines (21 loc) · 903 Bytes
/
Copy pathutils.ts
File metadata and controls
23 lines (21 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import type { AuthObject } from '@clerk/backend';
import { makeAuthObjectSerializable, stripPrivateDataFromObject } from '@clerk/backend/internal';
import type { InitialState } from '@clerk/types';
import type { H3Event } from 'h3';
import { getRequestHeaders, getRequestProtocol } from 'h3';
/**
* Converts an H3 event into a Fetch Request object.
*/
export function toWebRequest(event: H3Event) {
const headers = getRequestHeaders(event) as HeadersInit;
const protocol = getRequestProtocol(event);
const dummyOriginReqUrl = new URL(event.node.req.url || '', `${protocol}://clerk-dummy`);
return new Request(dummyOriginReqUrl, {
method: event.method,
headers: new Headers(headers),
});
}
export function createInitialState(auth: AuthObject) {
const initialState = makeAuthObjectSerializable(stripPrivateDataFromObject(auth));
return initialState as unknown as InitialState;
}