Skip to content

Commit cbf16aa

Browse files
committed
tsdoc client
1 parent 131c552 commit cbf16aa

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

packages/openauth/src/client.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,21 @@ export interface Client {
301301
* For SPA sites, the code is passed in through the URL hash.
302302
* :::
303303
*
304-
* This returns the access and refresh tokens. Or an error if something went wrong.
304+
* This returns the access and refresh tokens. Or if it fails it returns an error that you can
305+
* handle depending on the error.
305306
*
306307
* ```ts
307-
* if (exchanged.err) throw new Error(exchanged.err)
308+
* import { InvalidAuthorizationCodeError } from "@openauthjs/openauth/error"
309+
*
310+
* if (exchanged.err) {
311+
* if (exchanged.err instanceof InvalidAuthorizationCodeError) {
312+
* // handle invalid code error
313+
* }
314+
* else {
315+
* // handle other errors
316+
* }
317+
* }
318+
*
308319
* const { access, refresh } = exchanged.tokens
309320
* ```
310321
*

packages/openauth/src/error.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* The OAuth server returned an error.
3+
*/
14
export class OauthError extends Error {
25
constructor(
36
public error:
@@ -14,6 +17,9 @@ export class OauthError extends Error {
1417
}
1518
}
1619

20+
/**
21+
* The `provider` needs to be passed in.
22+
*/
1723
export class MissingProviderError extends OauthError {
1824
constructor() {
1925
super(
@@ -23,12 +29,18 @@ export class MissingProviderError extends OauthError {
2329
}
2430
}
2531

32+
/**
33+
* The given parameter is missing.
34+
*/
2635
export class MissingParameterError extends OauthError {
2736
constructor(public parameter: string) {
2837
super("invalid_request", "Missing parameter: " + parameter)
2938
}
3039
}
3140

41+
/**
42+
* The given client is not authorized to use the redirect URI that was passed in.
43+
*/
3244
export class UnauthorizedClientError extends OauthError {
3345
constructor(
3446
public clientID: string,
@@ -41,6 +53,12 @@ export class UnauthorizedClientError extends OauthError {
4153
}
4254
}
4355

56+
/**
57+
* The browser was in an unknown state.
58+
*
59+
* This can happen when certain cookies have expired. Or the browser was switched in the middle
60+
* of the authentication flow.
61+
*/
4462
export class UnknownStateError extends Error {
4563
constructor() {
4664
super(
@@ -49,24 +67,36 @@ export class UnknownStateError extends Error {
4967
}
5068
}
5169

70+
/**
71+
* The given subject is invalid.
72+
*/
5273
export class InvalidSubjectError extends Error {
5374
constructor() {
5475
super("Invalid subject")
5576
}
5677
}
5778

79+
/**
80+
* The given refresh token is invalid.
81+
*/
5882
export class InvalidRefreshTokenError extends Error {
5983
constructor() {
6084
super("Invalid refresh token")
6185
}
6286
}
6387

88+
/**
89+
* The given access token is invalid.
90+
*/
6491
export class InvalidAccessTokenError extends Error {
6592
constructor() {
6693
super("Invalid access token")
6794
}
6895
}
6996

97+
/**
98+
* The given authorization code is invalid.
99+
*/
70100
export class InvalidAuthorizationCodeError extends Error {
71101
constructor() {
72102
super("Invalid authorization code")

www/src/content/docs/docs/authorizer.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,19 @@ The interface for the success responder.
159159
## Errors
160160
### InvalidAccessTokenError
161161
<Segment>
162+
The given access token is invalid.
162163
</Segment>
163164
### InvalidAuthorizationCodeError
164165
<Segment>
166+
The given authorization code is invalid.
165167
</Segment>
166168
### InvalidRefreshTokenError
167169
<Segment>
170+
The given refresh token is invalid.
168171
</Segment>
169172
### InvalidSubjectError
170173
<Segment>
174+
The given subject is invalid.
171175
</Segment>
172176
### MissingParameterError
173177
<Segment>
@@ -183,5 +187,9 @@ The interface for the success responder.
183187
</Segment>
184188
### UnknownStateError
185189
<Segment>
190+
The browser was in an unknown state.
191+
192+
This can happen when certain cookies have expired. Or the browser was switched in the middle
193+
of the authentication flow.
186194
</Segment>
187195
</div>

www/src/content/docs/docs/storage/cloudflare.mdx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,27 @@ CloudflareStorage(options)
4040
</Section>
4141
<Section type="parameters">
4242
#### Parameters
43-
- <p><code class="key">options</code> <code class="type">CloudflareStorageOptions</code></p>
43+
- <p><code class="key">options</code> [<code class="type">CloudflareStorageOptions</code>](#cloudflarestorageoptions)</p>
4444
The config for the adapter.
4545
</Section>
4646
<InlineSection>
4747
**Returns** <code class="type">StorageAdapter</code>
4848
</InlineSection>
4949
Creates a Cloudflare KV store.
5050
</Segment>
51+
## CloudflareStorageOptions
52+
<Segment>
53+
<Section type="parameters">
54+
- <p>[<code class="key">namespace</code>](#cloudflarestorageoptions.namespace) <code class="type">KVNamespace</code></p>
55+
</Section>
56+
Configure the DynamoDB table that's created.
57+
</Segment>
58+
<NestedTitle id="cloudflarestorageoptions.namespace" Tag="h4" parent="CloudflareStorageOptions.">namespace</NestedTitle>
59+
<Segment>
60+
<Section type="parameters">
61+
<InlineSection>
62+
**Type** <code class="type">KVNamespace</code>
63+
</InlineSection>
64+
</Section>
65+
</Segment>
5166
</div>

0 commit comments

Comments
 (0)