Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
victoriaxyz committed Dec 13, 2024
1 parent aa41549 commit e6a9deb
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 86 deletions.
63 changes: 41 additions & 22 deletions docs/references/vue/use-auth.mdx
Original file line number Diff line number Diff line change
@@ -1,102 +1,121 @@
---
title: '`useAuth()`'
description: Clerk's useAuth() composable is a convenient way to access the current auth state.
description: Access and manage authentication state in your Vue application with Clerk's useAuth() composable.
---

The `useAuth()` composable provides information about the current auth state, as well as helper methods to manage the current active session.
The `useAuth()` composable provides access to the current authentication state and methods to manage the active session in your Vue application.

## `useAuth()` returns
## Usage

```vue
<script setup>
import { useAuth } from '@clerk/vue'
const { isSignedIn, getToken } = useAuth()
</script>
```

## Return values

<Properties>
- `isSignedIn`
- `isLoaded`
- `Ref<boolean>`

A boolean that returns true if the user is signed in.
A boolean that indicates whether Clerk has completed initialization. Initially `false`, becomes `true` once Clerk loads.

---

- `isLoaded`
- `isSignedIn`
- `Ref<boolean>`

A boolean that until Clerk loads and initializes, will be set to `false`. Once Clerk loads, `isLoaded` will be set to `true`.
A boolean that indicates whether a user is currently signed in.

---

- `userId`
- `Ref<string>`

The current user's ID.
The unique identifier of the current user.

---

- `sessionId`
- `Ref<string>`

The current user's session ID.
The unique identifier of the current session.

---

- `orgId`
- `Ref<string>`

The current user's active organization ID.
The unique identifier of the user's active organization.

---

- `orgRole`
- `Ref<string>`

The current user's active organization role.
The current user's role in their active organization.

---

- `orgSlug`
- `Ref<string>`

The current user's organization slug.
The URL-friendly identifier of the user's active organization.

---

- `signOut()`
- `Ref<(options?: SignOutOptions) => Promise<void>>`

A function that signs the user out. See the [reference documentation](/docs/references/javascript/clerk/clerk#sign-out) for more information.
A function that returns a promise that resolves when the current user is signed out. See the [reference doc](/docs/references/javascript/clerk/clerk#sign-out).

---

- `getToken()`
- `Ref<(options?: GetTokenOptions) => Promise<string | null>>`

A function that returns a promise that resolves to the current user's session token. Can also be used to retrieve a custom JWT template. See the [reference documentation](/docs/references/javascript/session#get-token) for more information.
A function that returns a promise that resolves to the current user's session token. Can also retrieve a custom JWT template. See the [reference doc](/docs/references/javascript/session#get-token).

---

- `has()`
- `Ref<(isAuthorizedParams: CheckAuthorizationParamsWithCustomPermissions) => boolean>`

A function that returns a boolean based on the permission or role provided as parameter. Can be used for authorization. See the [reference documentation](/docs/references/nextjs/auth-object#has){{ target: '_blank' }} for more information.
A function that returns a boolean indicating whether the user has specific permissions or roles. See the [reference doc](/docs/references/javascript/auth-object#has).
</Properties>

## How to use the `useAuth()` composable
## Example

The following example demonstrates how to use the `useAuth()` composable to access the current auth state, like whether the user is signed in or not. It also demonstrates a basic example of how you could use the `getToken()` method to retrieve a session token for fetching data from an external resource.
The following example demonstrates how to use `useAuth()` to access the authentication state, protect a page, and fetch data from an external API:

```vue {{ filename: 'external-data-page.vue' }}
```vue {{ filename: 'App.vue' }}
<script setup>
import { useAuth } from '@clerk/vue'
const { getToken, isLoaded, isSignedIn } = useAuth()
const fetchDataFromExternalResource = async () => {
const fetchProtectedData = async () => {
const token = await getToken.value()
// Add logic to fetch your data
return data
// Fetch data from an external API
const response = await fetch('https://api.example.com/data', {
headers: {
Authorization: `Bearer ${token}`,
},
})
return response.json()
}
</script>
<template>
<div v-if="!isLoaded">Loading...</div>
<div v-else-if="!isSignedIn">Sign in to view this page</div>
<div v-else>...</div>
<div v-else>
<!-- Your protected content here -->
</div>
</template>
```
18 changes: 9 additions & 9 deletions docs/references/vue/use-clerk.mdx
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
---
title: '`useClerk()`'
description: Clerk's useClerk() composable is used to access the Clerk object, which can be used to build alternatives to any Clerk Component.
description: Access and manage the Clerk instance in your Vue application with Clerk's useClerk() composable.
---

The `useClerk()` composable is a convenient way to access to the [`Clerk`](/docs/references/javascript/clerk/clerk) object, giving you the ability to build alternatives to any Clerk Component.

> [!WARNING]
> This is intended to be used for advanced use cases, like building a completely custom OAuth flow or as an escape hatch for getting access to the `Clerk` object.
## `useClerk()` returns
> This composable should only be used for advanced use cases, such as building a completely custom OAuth flow or as an escape hatch to access to the `Clerk` object.
The `useClerk()` composable returns the `Clerk` object, which includes all the methods and properties listed in the [`Clerk` reference](/docs/references/javascript/clerk/clerk).
The `useClerk()` composable provides access to the [`Clerk`](/docs/references/javascript/clerk/clerk) object, giving you the ability to build alternatives to any [Clerk component](/docs/components/overview).

## How to use the `useClerk()` composable
## Usage

```vue {{ filename: 'home.vue' }}
```vue
<script setup>
import { useClerk } from '@clerk/vue'
Expand All @@ -25,3 +21,7 @@ const clerk = useClerk()
<button @click="clerk.openSignIn">Sign in</button>
</template>
```

## Return Value

The `useClerk()` composable returns the `Clerk` object, which includes all the methods and properties listed in the [`Clerk` reference](/docs/references/javascript/clerk/clerk).
95 changes: 71 additions & 24 deletions docs/references/vue/use-sign-in.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
---
title: '`useSignIn()`'
description: Clerk's useSignIn() composable provides access to the SignIn object, which allows you to check the current state of a sign-in.
description: Access and manage sign-in state in your Vue application with Clerk's useSignIn() composable.
---

The `useSignIn()` composable provides access to the [`SignIn`](/docs/references/javascript/sign-in/sign-in) object, which allows you to check the current state of a sign-in. This is also useful for creating a [custom sign-in flow.](#create-a-custom-sign-in-flow-with-use-sign-in)
The `useSignIn()` composable provides access to the [`SignIn`](/docs/references/javascript/sign-in/sign-in) object, which allows you to check the current state of a sign-in attempt and manage the sign-in flow. You can use this to create a [custom sign-in flow](/docs/custom-flows/overview#sign-in-flow).

## `useSignIn()` returns
## Usage

```vue
<script setup>
import { useSignIn } from '@clerk/vue'
const { isLoaded, signIn, setActive } = useSignIn()
</script>
```

```ts
function useSignIn(): {
isLoaded: Ref<boolean>
signIn: Ref<SignIn>
setActive: Ref<(params: SetActiveParams) => Promise<void>>
}
```

## Reference

### Return values

<Properties>
- `isLoaded`
- `Ref<boolean>`

A boolean that is set to `false` until Clerk loads and initializes.
A boolean that indicates whether Clerk has completed initialization. Initially `false`, becomes `true` once Clerk loads.

---

Expand All @@ -28,7 +48,9 @@ The `useSignIn()` composable provides access to the [`SignIn`](/docs/references/
An object that contains the current sign-in attempt status and methods to create a new sign-in attempt.
</Properties>

### `SetActiveParams`
### Types

#### `SetActiveParams`

<Properties>
- `session`
Expand All @@ -48,16 +70,55 @@ The `useSignIn()` composable provides access to the [`SignIn`](/docs/references/
- `beforeEmit?`
- `(session?: Session | null) => void | Promise<any>`

Callback run just before the active session and/or organization is set to the passed object. Can be used to composable up for pre-navigation actions.
Callback run just before the active session and/or organization is set to the passed object. Can be used to set up for pre-navigation actions.
</Properties>

## How to use the `useSignIn()` composable
#### `SignIn` status values

The `status` property of the `SignIn` object can be one of the following values:

<Properties>
- `complete`
- `string`

The user is signed in and the custom flow can proceed to `setActive()` to create session.

---

### Check the current state of a sign-in with `useSignIn()`
- `needs_first_factor`
- `string`

Use the `useSignIn()` composable to check the current state of a sign-in.
One of the following [first factor verification strategies](/docs/references/javascript/sign-in/first-factor) is missing: `email_link`, `email_code`, `phone_code`, `web3_metamask_signature`, `web3_coinbase_wallet_signature` or `oauth_provider`.

---

```vue {{ filename: 'pages/sign-in-step.vue' }}
- `needs_second_factor`
- `string`

One of the following [second factor verification strategies](/docs/references/javascript/sign-in/second-factor) is missing: `phone_code` or `totp`. This value is optional.

---

- `needs_identifier`
- `string`

The user's identifier (e.g., email address, phone number, username) hasn't been provided.

---

- `needs_new_password`
- `string`

The user needs to set a new password.
</Properties>

## Example

### Check and show sign-in status

The following example checks the current sign-in status and displays the value in the UI.

```vue {{ filename: 'SignInPage.vue' }}
<script setup>
import { useSignIn } from '@clerk/vue'
Expand All @@ -72,17 +133,3 @@ const { isLoaded, signIn } = useSignIn()
<div v-else>The current sign in attempt status is {{ signIn.status }}.</div>
</template>
```

The `status` property of the `SignIn` object can be one of the following values:

| Values | Descriptiom |
| - | - |
| `complete` | The user has been signed in and custom flow can proceed to `setActive()` to create session. |
| `needs_first_factor` | The First Factor verification is missing. One of `email_link`, `email_code`, `phone_code`, `web3_metamask_signature`, `web3_coinbase_wallet_signature` or `oauth_provider` is required to verify user. See [First Factor](/docs/references/javascript/sign-in/first-factor) for details. |
| `needs_second_factor` | The Second Factor verification is missing. The Second Factor is an optional step to provide additional verification and includes `phone_code` and `totp`. See [Second Factor](/docs/references/javascript/sign-in/second-factor) for details. |
| `needs_identifier` | The user's identifier (email address, phone number, username, etc.) hasn't been provided. |
| `needs_new_password` | The user needs to set a new password. |

### Create a custom sign-in flow with `useSignIn()`

The `useSignIn()` composable can also be used to build fully custom sign-in flows, if Clerk's prebuilt components don't meet your specific needs or if you require more control over the authentication flow. Different sign-in flows include email and password, email and phone codes, email links, and multifactor (MFA). To learn more about using the `useSignIn()` composable to create custom flows, check out the [custom flow guides](/docs/custom-flows/overview).
Loading

0 comments on commit e6a9deb

Please sign in to comment.