-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to disable redirect in
useAuth
hook when a user is unaut…
…henticated (#531) * Add option to disable redirect in `useAuth` hook Introduced `UseAuthOptions` that allows a user to specify the `shouldRedirect` property. This property defines if the `useAuth` hook should redirect to the appropriate url when unauthenticated. * `UseAuthOptions` docs Describe the new `UseAuthOptions` properties and provide examples * `UseAuthOptions` changeset * Changeset for `Content-Type` header fix * Fix middleware tests Added `setHeader` to res mock * Use lodash defaults for `UseAuthOptions`
- Loading branch information
1 parent
647020b
commit 5c7f662
Showing
9 changed files
with
138 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
'@faustjs/next': minor | ||
--- | ||
|
||
Introduced an argument to the `useAuth` hook, `UseAuthOptions`, to provide users the ability to disable automatic redirect from the `useAuth` hook upon an unauthenticated user. | ||
|
||
```tsx | ||
import { client } from 'client'; | ||
|
||
export default function Page() { | ||
const { isLoading, isAuthenticated, authResult } = client.auth.useAuth({ | ||
shouldRedirect: false, | ||
}); | ||
|
||
if (isLoading) { | ||
return <p>Loading...</p>; | ||
} | ||
|
||
if (!isAuthenticated) { | ||
return ( | ||
<p>You need to be authenticated to see this content. Please login.</p> | ||
); | ||
} | ||
|
||
return <p>Authenticated content</p>; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@faustjs/core': patch | ||
--- | ||
|
||
Added the appropriate `Content-Type` response header to the `authorizeHandler` middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters