Skip to content

Commit c331011

Browse files
docs: improve auth subscription readability (#455)
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent d819af8 commit c331011

8 files changed

Lines changed: 87 additions & 84 deletions

File tree

docs/build/authentication/development.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,26 @@ This will clear the sign-in information stored in IndexedDB.
7373

7474
---
7575

76-
## Subscription
76+
## Listening to Auth Changes
7777

78-
You can subscribe to the user state using the subscriber function. This function provides a technical user and triggers whenever the user's state changes.
79-
80-
In other words, using this callback allows you to monitor whether the user is signed in or signed out.
78+
You can monitor when a user signs in or out using `authSubscribe`. It gives you the current user and notifies you whenever their authentication state changes.
8179

8280
```typescript
8381
import { authSubscribe } from "@junobuild/core";
8482

83+
// Reactively track if the user is signed in or signed out
8584
authSubscribe((user: User | null) => {
8685
console.log("User:", user);
8786
});
8887
```
8988

90-
If you register the subscriber at the top of your application, it will propagate the user's state accordingly (e.g. `null` when a new user opens the app, the new user's entry when they sign in, the existing user when they refresh the browser within the valid duration, and `null` again when they sign out).
89+
If you register the subscriber at the top of your application, it will automatically reflect the user's state:
90+
91+
- `null` when the app first loads and the user is not signed in
92+
- A `User` object when they sign in or refresh while authenticated
93+
- `null` again when they sign out
9194

92-
Subscribing returns a callback that can be executed to unsubscribe:
95+
To stop listening, you can call the unsubscribe function returned:
9396

9497
```typescript
9598
import { authSubscribe } from "@junobuild/core";
@@ -98,7 +101,7 @@ const unsubscribe = authSubscribe((user: User | null) => {
98101
console.log("User:", user);
99102
});
100103

101-
// Above subscriber ends now
104+
// Stop listening
102105
unsubscribe();
103106
```
104107

docs/examples/angular.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ import HowToRun from "./components/how-to-run.md";
116116

117117
The following functions from `@junobuild/core` are used in this example:
118118

119-
| Function | Purpose/Description | Where Used (File/Component) | Juno Docs/Source Reference |
120-
| --------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
121-
| `initSatellite` | Initialize Juno Satellite container | [`src/app/app.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/app.component.ts) | [Initialization](../setup-the-sdk#initialization) |
122-
| `authSubscribe` | Subscribe to auth state changes | [`src/app/services/auth.service.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/services/auth.service.ts) | [Subscription](../build/authentication/development#subscription) |
123-
| `signIn` | Sign in user | [`src/app/components/login/login.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/login/login.component.ts) | [Sign-in](../build/authentication/development#sign-in) |
124-
| `signOut` | Sign out user | [`src/app/components/logout/logout.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/logout/logout.component.ts) | [Sign-out](../build/authentication/development#sign-out) |
125-
| `listDocs` | List documents in a collection | [`src/app/services/docs.service.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/services/docs.service.ts) | [List documents](../build/datastore/development#list-documents) |
126-
| `setDoc` | Create or update a document | [`src/app/components/modal/modal.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/modal/modal.component.ts) | [Add a document](../build/datastore/development#add-a-document) |
127-
| `deleteDoc` | Delete a document | [`src/app/components/delete/delete.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/delete/delete.component.ts) | [Delete a document](../build/datastore/development#delete-a-document) |
128-
| `uploadFile` | Upload a file to storage | [`src/app/components/modal/modal.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/modal/modal.component.ts) | [Upload asset](../build/storage/development#upload-asset) |
129-
| `deleteAsset` | Delete a file from storage | [`src/app/components/delete/delete.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/delete/delete.component.ts) | [Delete asset](../build/storage/development#delete-asset) |
119+
| Function | Purpose/Description | Where Used (File/Component) | Juno Docs/Source Reference |
120+
| --------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
121+
| `initSatellite` | Initialize Juno Satellite container | [`src/app/app.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/app.component.ts) | [Initialization](../setup-the-sdk#initialization) |
122+
| `authSubscribe` | Subscribe to auth state changes | [`src/app/services/auth.service.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/services/auth.service.ts) | [Listening to Auth Changes](../build/authentication/development#listening-to-auth-changes) |
123+
| `signIn` | Sign in user | [`src/app/components/login/login.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/login/login.component.ts) | [Sign-in](../build/authentication/development#sign-in) |
124+
| `signOut` | Sign out user | [`src/app/components/logout/logout.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/logout/logout.component.ts) | [Sign-out](../build/authentication/development#sign-out) |
125+
| `listDocs` | List documents in a collection | [`src/app/services/docs.service.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/services/docs.service.ts) | [List documents](../build/datastore/development#list-documents) |
126+
| `setDoc` | Create or update a document | [`src/app/components/modal/modal.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/modal/modal.component.ts) | [Add a document](../build/datastore/development#add-a-document) |
127+
| `deleteDoc` | Delete a document | [`src/app/components/delete/delete.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/delete/delete.component.ts) | [Delete a document](../build/datastore/development#delete-a-document) |
128+
| `uploadFile` | Upload a file to storage | [`src/app/components/modal/modal.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/modal/modal.component.ts) | [Upload asset](../build/storage/development#upload-asset) |
129+
| `deleteAsset` | Delete a file from storage | [`src/app/components/delete/delete.component.ts`](https://github.com/junobuild/create-juno/blob/main/templates/angular-example/src/app/components/delete/delete.component.ts) | [Delete asset](../build/storage/development#delete-asset) |

docs/examples/nextjs.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ juno deploy
116116

117117
The following functions from `@junobuild/core` are used in this example:
118118

119-
| Function | Purpose/Description | Where Used (File/Component) | Juno Docs/Source Reference |
120-
| --------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------- |
121-
| `initSatellite` | Initialize Juno Satellite container | [`src/app/page.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/app/page.tsx) | [Initialization](../setup-the-sdk#initialization) |
122-
| `authSubscribe` | Subscribe to auth state changes | [`src/components/auth.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/auth.tsx) | [Subscription](../build/authentication/development#subscription) |
123-
| `signIn` | Sign in user | [`src/components/login.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/login.tsx) | [Sign-in](../build/authentication/development#sign-in) |
124-
| `signOut` | Sign out user | [`src/components/logout.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/logout.tsx) | [Sign-out](../build/authentication/development#sign-out) |
125-
| `listDocs` | List documents in a collection | [`src/components/table.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/table.tsx) | [List documents](../build/datastore/development#list-documents) |
126-
| `setDoc` | Create or update a document | [`src/components/modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/modal.tsx) | [Add a document](../build/datastore/development#add-a-document) |
127-
| `deleteDoc` | Delete a document | [`src/components/delete.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/delete.tsx) | [Delete a document](../build/datastore/development#delete-a-document) |
128-
| `uploadFile` | Upload a file to storage | [`src/components/modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/modal.tsx) | [Upload asset](../build/storage/development#upload-asset) |
129-
| `deleteAsset` | Delete a file from storage | [`src/components/delete.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/delete.tsx) | [Delete asset](../build/storage/development#delete-asset) |
119+
| Function | Purpose/Description | Where Used (File/Component) | Juno Docs/Source Reference |
120+
| --------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
121+
| `initSatellite` | Initialize Juno Satellite container | [`src/app/page.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/app/page.tsx) | [Initialization](../setup-the-sdk#initialization) |
122+
| `authSubscribe` | Subscribe to auth state changes | [`src/components/auth.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/auth.tsx) | [Listening to Auth Changes](../build/authentication/development#listening-to-auth-changes) |
123+
| `signIn` | Sign in user | [`src/components/login.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/login.tsx) | [Sign-in](../build/authentication/development#sign-in) |
124+
| `signOut` | Sign out user | [`src/components/logout.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/logout.tsx) | [Sign-out](../build/authentication/development#sign-out) |
125+
| `listDocs` | List documents in a collection | [`src/components/table.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/table.tsx) | [List documents](../build/datastore/development#list-documents) |
126+
| `setDoc` | Create or update a document | [`src/components/modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/modal.tsx) | [Add a document](../build/datastore/development#add-a-document) |
127+
| `deleteDoc` | Delete a document | [`src/components/delete.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/delete.tsx) | [Delete a document](../build/datastore/development#delete-a-document) |
128+
| `uploadFile` | Upload a file to storage | [`src/components/modal.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/modal.tsx) | [Upload asset](../build/storage/development#upload-asset) |
129+
| `deleteAsset` | Delete a file from storage | [`src/components/delete.tsx`](https://github.com/junobuild/create-juno/blob/main/templates/nextjs-example/src/components/delete.tsx) | [Delete asset](../build/storage/development#delete-asset) |

0 commit comments

Comments
 (0)