-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export types and simplify hook checks and add docs
- Loading branch information
1 parent
3021947
commit 29a9f1a
Showing
5 changed files
with
99 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
"use client"; | ||
|
||
import { useMutation, type UseMutateFunction } from "@tanstack/react-query"; | ||
import { useAlchemyAccountContext } from "../context.js"; | ||
import type { BaseHookMutationArgs } from "../types.js"; | ||
import { useSigner } from "./useSigner.js"; | ||
|
||
export type UseLogoutData = void; | ||
|
||
export type UseLogoutParams = void; | ||
|
||
export type UseLogoutMutationArgs = BaseHookMutationArgs< | ||
UseLogoutData, | ||
UseLogoutParams | ||
>; | ||
|
||
export type UseLogoutResult = { | ||
logout: UseMutateFunction<UseLogoutData, Error, UseLogoutParams, unknown>; | ||
isLoggingOut: boolean; | ||
error: Error | null; | ||
}; | ||
|
||
export function useLogout( | ||
mutationArgs?: UseLogoutMutationArgs | ||
): UseLogoutResult { | ||
const { queryClient } = useAlchemyAccountContext(); | ||
const signer = useSigner(); | ||
|
||
const { | ||
mutate: logout, | ||
isPending: isLoggingOut, | ||
error, | ||
} = useMutation( | ||
{ | ||
mutationFn: signer!.disconnect, | ||
...mutationArgs, | ||
}, | ||
queryClient | ||
); | ||
|
||
return { | ||
logout, | ||
isLoggingOut, | ||
error, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
outline: deep | ||
head: | ||
- - meta | ||
- property: og:title | ||
content: useLogout | ||
- - meta | ||
- name: description | ||
content: An overview of the useLogout hook | ||
- - meta | ||
- property: og:description | ||
content: An overview of the useLogout hook | ||
- - meta | ||
- name: twitter:title | ||
content: useLogout | ||
- - meta | ||
- name: twitter:description | ||
content: An overview of the useLogout hook | ||
--- | ||
|
||
# useLogout | ||
|
||
The `useLogout` hook logs a user out of their Embedded Account on your application. | ||
|
||
## Import | ||
|
||
```ts | ||
import { useLogout } from "@alchemy/aa-alchemy/react"; | ||
``` | ||
|
||
## Usage | ||
|
||
<<< @/snippets/react/useLogout.tsx | ||
|
||
## Return Type | ||
|
||
```ts | ||
import { type useLogoutResult } from "@alchemy/aa-alchemy/react"; | ||
``` |
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,12 @@ | ||
import { useLogout } from "@alchemy/aa-alchemy/react"; | ||
|
||
export function ComponentWithUser() { | ||
// Assumes the app has context of a signer with an authenticated user | ||
const { logout } = useLogout(); | ||
|
||
return ( | ||
<div> | ||
<button onClick={() => logout}>Add Passkey</button> | ||
</div> | ||
); | ||
} |