codeforlife 2.7.0 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/api/endpoints/session.ts +0 -1
- package/src/hooks/auth.tsx +30 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.7.1](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.7.0...v2.7.1) (2025-08-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* optionally set useSessionMetadata ([22c5253](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/22c525341badef6f13fe9adc1489d033792d2340))
|
|
7
|
+
|
|
1
8
|
# [2.7.0](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.17...v2.7.0) (2025-08-15)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/hooks/auth.tsx
CHANGED
|
@@ -15,10 +15,7 @@ import {
|
|
|
15
15
|
type OAuth2RequestCodeUrlSearchParams,
|
|
16
16
|
type OAuth2ReceiveCodeUrlSearchParams,
|
|
17
17
|
} from "../utils/auth"
|
|
18
|
-
import {
|
|
19
|
-
type ExchangeOAuth2CodeResult,
|
|
20
|
-
type ExchangeOAuth2CodeArg,
|
|
21
|
-
} from "../api/endpoints/session"
|
|
18
|
+
import { type ExchangeOAuth2CodeArg } from "../api/endpoints/session"
|
|
22
19
|
import { useSearchParams, useLocation, useNavigate } from "./router"
|
|
23
20
|
import { SESSION_METADATA_COOKIE_NAME } from "../settings"
|
|
24
21
|
import { selectIsLoggedIn } from "../slices/session"
|
|
@@ -198,7 +195,7 @@ export function useOAuth2CodeChallenge(
|
|
|
198
195
|
return [_codeChallenge, resetCodeChallenge]
|
|
199
196
|
}
|
|
200
197
|
|
|
201
|
-
|
|
198
|
+
interface BaseUseOAuth2KwArgs<SessionMetadata> {
|
|
202
199
|
provider: string
|
|
203
200
|
authUri: string
|
|
204
201
|
clientId: string
|
|
@@ -207,15 +204,24 @@ export interface UseOAuth2KwArgs<ResultType = ExchangeOAuth2CodeResult> {
|
|
|
207
204
|
responseType?: "code"
|
|
208
205
|
accessType?: "offline"
|
|
209
206
|
prompt?: string
|
|
210
|
-
useLoginMutation: TypedUseMutation<
|
|
211
|
-
|
|
207
|
+
useLoginMutation: TypedUseMutation<
|
|
208
|
+
SessionMetadata,
|
|
209
|
+
ExchangeOAuth2CodeArg,
|
|
210
|
+
any
|
|
211
|
+
>
|
|
212
|
+
onCreateSession: (result: SessionMetadata) => void
|
|
212
213
|
onRetrieveSession: (metadata: SessionMetadata) => void
|
|
213
214
|
}
|
|
214
215
|
|
|
216
|
+
interface UseOAuth2KwArgs<SessionMetadata>
|
|
217
|
+
extends BaseUseOAuth2KwArgs<SessionMetadata> {
|
|
218
|
+
useSessionMetadata: () => SessionMetadata | undefined
|
|
219
|
+
}
|
|
220
|
+
|
|
215
221
|
export type OAuth2 = [string, OAuth2RequestCodeUrlSearchParams] | []
|
|
216
222
|
|
|
217
223
|
// https://datatracker.ietf.org/doc/html/rfc7636
|
|
218
|
-
|
|
224
|
+
function _useOAuth2<SessionMetadata>({
|
|
219
225
|
provider,
|
|
220
226
|
authUri,
|
|
221
227
|
clientId,
|
|
@@ -224,10 +230,11 @@ export function useOAuth2<ResultType = ExchangeOAuth2CodeResult>({
|
|
|
224
230
|
responseType = "code",
|
|
225
231
|
accessType = "offline",
|
|
226
232
|
prompt,
|
|
233
|
+
useSessionMetadata,
|
|
227
234
|
useLoginMutation,
|
|
228
235
|
onCreateSession,
|
|
229
236
|
onRetrieveSession,
|
|
230
|
-
}: UseOAuth2KwArgs<
|
|
237
|
+
}: UseOAuth2KwArgs<SessionMetadata>): OAuth2 {
|
|
231
238
|
const [state, resetState] = useOAuth2State(provider)
|
|
232
239
|
const [
|
|
233
240
|
{
|
|
@@ -280,7 +287,7 @@ export function useOAuth2<ResultType = ExchangeOAuth2CodeResult>({
|
|
|
280
287
|
// ...and the page's state contains the stored state...
|
|
281
288
|
locationState.state === state &&
|
|
282
289
|
// ...and the login endpoint was not called with the current values or has
|
|
283
|
-
// not returned
|
|
290
|
+
// not returned an error...
|
|
284
291
|
(loginArgs.code !== locationState.code ||
|
|
285
292
|
loginArgs.code_verifier !== codeVerifier ||
|
|
286
293
|
loginArgs.redirect_uri !== redirectUri ||
|
|
@@ -362,3 +369,16 @@ export function useOAuth2<ResultType = ExchangeOAuth2CodeResult>({
|
|
|
362
369
|
|
|
363
370
|
return []
|
|
364
371
|
}
|
|
372
|
+
|
|
373
|
+
export const useOAuth2: {
|
|
374
|
+
<SessionMetadata>(kwargs: UseOAuth2KwArgs<SessionMetadata>): OAuth2
|
|
375
|
+
(kwargs: BaseUseOAuth2KwArgs<SessionMetadata>): OAuth2
|
|
376
|
+
} = <_SessionMetadata,>(
|
|
377
|
+
kwargs:
|
|
378
|
+
| UseOAuth2KwArgs<_SessionMetadata>
|
|
379
|
+
| BaseUseOAuth2KwArgs<SessionMetadata>,
|
|
380
|
+
): OAuth2 => {
|
|
381
|
+
return "useSessionMetadata" in kwargs
|
|
382
|
+
? _useOAuth2(kwargs)
|
|
383
|
+
: _useOAuth2({ ...kwargs, useSessionMetadata })
|
|
384
|
+
}
|