You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/build/authentication/development.md
+10-7Lines changed: 10 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,23 +73,26 @@ This will clear the sign-in information stored in IndexedDB.
73
73
74
74
---
75
75
76
-
## Subscription
76
+
## Listening to Auth Changes
77
77
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.
81
79
82
80
```typescript
83
81
import { authSubscribe } from"@junobuild/core";
84
82
83
+
// Reactively track if the user is signed in or signed out
85
84
authSubscribe((user:User|null) => {
86
85
console.log("User:", user);
87
86
});
88
87
```
89
88
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
91
94
92
-
Subscribing returns a callback that can be executed to unsubscribe:
95
+
To stop listening, you can call the unsubscribe function returned:
|`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 |
|`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)|
|`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 |
|`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