@mentra/react 0.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/dist/AuthProvider.d.ts +3 -3
- package/dist/AuthProvider.d.ts.map +1 -1
- package/dist/AuthProvider.js +5 -5
- package/dist/AuthProvider.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/authCore.d.ts.map +1 -1
- package/dist/lib/authCore.js +5 -6
- package/dist/lib/authCore.js.map +1 -1
- package/dist/useMentraosAuth.d.ts +16 -0
- package/dist/useMentraosAuth.d.ts.map +1 -0
- package/dist/useMentraosAuth.js +24 -0
- package/dist/useMentraosAuth.js.map +1 -0
- package/package.json +1 -1
- package/dist/useMentraAuth.d.ts +0 -16
- package/dist/useMentraAuth.d.ts.map +0 -1
- package/dist/useMentraAuth.js +0 -24
- package/dist/useMentraAuth.js.map +0 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ yarn add @mentra/react
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
-
### 1. Wrap your application with `
|
|
24
|
+
### 1. Wrap your application with `MentraosAuthProvider`
|
|
25
25
|
|
|
26
26
|
In your main application file (e.g., `src/main.tsx` or `src/index.tsx`):
|
|
27
27
|
|
|
@@ -30,28 +30,28 @@ In your main application file (e.g., `src/main.tsx` or `src/index.tsx`):
|
|
|
30
30
|
import React from 'react';
|
|
31
31
|
import ReactDOM from 'react-dom/client';
|
|
32
32
|
import App from './App';
|
|
33
|
-
import {
|
|
33
|
+
import { MentraosAuthProvider } from '@mentra/react';
|
|
34
34
|
|
|
35
35
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
36
36
|
<React.StrictMode>
|
|
37
|
-
<
|
|
37
|
+
<MentraosAuthProvider>
|
|
38
38
|
<App />
|
|
39
|
-
</
|
|
39
|
+
</MentraosAuthProvider>
|
|
40
40
|
</React.StrictMode>
|
|
41
41
|
);
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
### 2. Access authentication state using `
|
|
44
|
+
### 2. Access authentication state using `useMentraosAuth`
|
|
45
45
|
|
|
46
46
|
In any component that needs user information:
|
|
47
47
|
|
|
48
48
|
```tsx
|
|
49
49
|
// src/MyComponent.tsx
|
|
50
50
|
import React from 'react';
|
|
51
|
-
import {
|
|
51
|
+
import { useMentraosAuth } from '@mentra/react';
|
|
52
52
|
|
|
53
53
|
const MyComponent = () => {
|
|
54
|
-
const { userId, frontendToken, isLoading, error, isAuthenticated, logout } =
|
|
54
|
+
const { userId, frontendToken, isLoading, error, isAuthenticated, logout } = useMentraosAuth();
|
|
55
55
|
|
|
56
56
|
if (isLoading) {
|
|
57
57
|
return <p>Loading authentication...</p>;
|
|
@@ -89,19 +89,19 @@ export default MyComponent;
|
|
|
89
89
|
## How It Works
|
|
90
90
|
|
|
91
91
|
1. When your webview is loaded by the MentraOS manager, it appends an `aos_signed_user_token` (a JWT) as a URL query parameter.
|
|
92
|
-
2. The `
|
|
92
|
+
2. The `MentraosAuthProvider` attempts to find this token.
|
|
93
93
|
3. It verifies the token's signature against the MentraOS Cloud public key and checks its claims (like issuer and expiration).
|
|
94
94
|
4. If valid, it extracts the `userId` (from the `sub` claim) and a `frontendToken` (another JWT from the payload).
|
|
95
|
-
5. These `userId` and `frontendToken` are then stored in `localStorage` and made available via the `
|
|
95
|
+
5. These `userId` and `frontendToken` are then stored in `localStorage` and made available via the `useMentraosAuth` hook.
|
|
96
96
|
6. If the token is not found in the URL (e.g., on a page refresh within the webview), the provider attempts to load the `userId` and `frontendToken` from `localStorage`.
|
|
97
97
|
|
|
98
98
|
## Making Authenticated Calls to Your App Backend
|
|
99
99
|
|
|
100
|
-
The `frontendToken` obtained from `
|
|
100
|
+
The `frontendToken` obtained from `useMentraosAuth` is a JWT. You should send this token in the `Authorization` header as a Bearer token when making requests from your webview to **your App's backend API**. The MentraOS SDK will automatically verify this token.
|
|
101
101
|
|
|
102
102
|
```typescript
|
|
103
103
|
// Example of an authenticated API call
|
|
104
|
-
const { frontendToken } =
|
|
104
|
+
const { frontendToken } = useMentraosAuth();
|
|
105
105
|
|
|
106
106
|
async function fetchDataFromMyBackend(): Promise<void> {
|
|
107
107
|
if (!frontendToken) {
|
|
@@ -132,7 +132,7 @@ async function fetchDataFromMyBackend(): Promise<void> {
|
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
> **Note:**
|
|
135
|
-
> If your
|
|
135
|
+
> If your App webview is hosted on a different domain or port than your backend API, make sure your backend's CORS (Cross-Origin Resource Sharing) policy allows requests from the webview's origin.
|
|
136
136
|
> For example, if your backend is at `https://your-app-backend.example.com` and your webview is loaded from `https://some-other-frontend.com`, your backend must explicitly allow cross-origin requests from `https://some-other-frontend.com` (or use a wildcard for development, but restrict in production).
|
|
137
137
|
>
|
|
138
138
|
> **Example in the backend:**
|
|
@@ -151,10 +151,10 @@ async function fetchDataFromMyBackend(): Promise<void> {
|
|
|
151
151
|
|
|
152
152
|
## TypeScript Support
|
|
153
153
|
|
|
154
|
-
This library includes full TypeScript support. The `
|
|
154
|
+
This library includes full TypeScript support. The `useMentraosAuth` hook returns a typed object with the following interface:
|
|
155
155
|
|
|
156
156
|
```typescript
|
|
157
|
-
interface
|
|
157
|
+
interface MentraosAuthContextType {
|
|
158
158
|
userId: string | null;
|
|
159
159
|
frontendToken: string | null;
|
|
160
160
|
isLoading: boolean;
|
package/dist/AuthProvider.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { AuthState } from './lib/authCore';
|
|
3
|
-
export interface
|
|
3
|
+
export interface MentraosAuthContextType extends AuthState {
|
|
4
4
|
isLoading: boolean;
|
|
5
5
|
error: string | null;
|
|
6
6
|
logout: () => void;
|
|
7
7
|
isAuthenticated: boolean;
|
|
8
8
|
}
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
9
|
+
export declare const MentraosAuthContext: React.Context<MentraosAuthContextType | undefined>;
|
|
10
|
+
export declare const MentraosAuthProvider: ({ children }: {
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
13
13
|
//# sourceMappingURL=AuthProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../src/AuthProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAsC,SAAS,EAAe,MAAM,OAAO,CAAC;AAC1F,OAAO,EAAmC,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE5E,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../src/AuthProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAsC,SAAS,EAAe,MAAM,OAAO,CAAC;AAC1F,OAAO,EAAmC,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE5E,MAAM,WAAW,uBAAwB,SAAQ,SAAS;IACxD,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,eAAO,MAAM,mBAAmB,oDAAgE,CAAC;AAEjG,eAAO,MAAM,oBAAoB,GAAI,cAAc;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,4CAyCzE,CAAC"}
|
package/dist/AuthProvider.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
//
|
|
2
|
+
// react-sdk/src/AuthProvider.tsx
|
|
3
3
|
import { createContext, useState, useEffect, useCallback } from 'react';
|
|
4
4
|
import { initializeAuth, clearStoredAuth } from './lib/authCore';
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
5
|
+
export const MentraosAuthContext = createContext(undefined);
|
|
6
|
+
export const MentraosAuthProvider = ({ children }) => {
|
|
7
7
|
const [userId, setUserId] = useState(null);
|
|
8
8
|
const [frontendToken, setFrontendToken] = useState(null);
|
|
9
9
|
const [isLoading, setIsLoading] = useState(true);
|
|
@@ -17,7 +17,7 @@ export const MentraAuthProvider = ({ children }) => {
|
|
|
17
17
|
setFrontendToken(auth.frontendToken);
|
|
18
18
|
}
|
|
19
19
|
catch (e) {
|
|
20
|
-
console.error("
|
|
20
|
+
console.error("MentraOS Auth Initialization Error:", e);
|
|
21
21
|
setError(e.message || 'Unknown authentication error');
|
|
22
22
|
clearStoredAuth(); // Clear any potentially bad stored state
|
|
23
23
|
setUserId(null);
|
|
@@ -36,6 +36,6 @@ export const MentraAuthProvider = ({ children }) => {
|
|
|
36
36
|
setFrontendToken(null);
|
|
37
37
|
}, []);
|
|
38
38
|
const isAuthenticated = !!userId && !!frontendToken;
|
|
39
|
-
return (_jsx(
|
|
39
|
+
return (_jsx(MentraosAuthContext.Provider, { value: { userId, frontendToken, isLoading, error, logout, isAuthenticated }, children: children }));
|
|
40
40
|
};
|
|
41
41
|
//# sourceMappingURL=AuthProvider.js.map
|
package/dist/AuthProvider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthProvider.js","sourceRoot":"","sources":["../src/AuthProvider.tsx"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"AuthProvider.js","sourceRoot":"","sources":["../src/AuthProvider.tsx"],"names":[],"mappings":";AAAA,iCAAiC;AACjC,OAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAa,WAAW,EAAE,MAAM,OAAO,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,eAAe,EAAa,MAAM,gBAAgB,CAAC;AAS5E,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAa,CAAsC,SAAS,CAAC,CAAC;AAEjG,MAAM,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Ae,EAAE,CAAC;QAClB,SAAS,CAAC,IAAI,CAAC,CAAC;QAChB,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,aAAa,CAAC;IAEpD,OAAO,CACL,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,YACtG,QAAQ,GACoB,CAChC,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { MentraosAuthProvider } from './AuthProvider';
|
|
2
|
+
export { useMentraosAuth } from './useMentraosAuth';
|
|
3
3
|
export type { AuthState } from './lib/authCore';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
// react-sdk/src/index.ts
|
|
2
|
+
export { MentraosAuthProvider } from './AuthProvider';
|
|
3
|
+
export { useMentraosAuth } from './useMentraosAuth';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authCore.d.ts","sourceRoot":"","sources":["../../src/lib/authCore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authCore.d.ts","sourceRoot":"","sources":["../../src/lib/authCore.ts"],"names":[],"mappings":"AAkCA,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AA0DD;;;GAGG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,SAAS,CAAC,CAkCzD;AAED,wBAAgB,aAAa,IAAI,SAAS,CAIzC;AAED,wBAAgB,eAAe,IAAI,IAAI,CAGtC"}
|
package/dist/lib/authCore.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
//
|
|
1
|
+
// react-sdk/src/lib/authCore.ts
|
|
2
2
|
import { KEYUTIL, KJUR } from 'jsrsasign'; // Assuming jsrsasign is available
|
|
3
|
-
// This should be the
|
|
4
|
-
// It's a public key, so embedding it is generally fine.
|
|
3
|
+
// This should be the MentraOS Cloud's public key for verifying aos_signed_user_token
|
|
5
4
|
const userTokenPublicKeyPEM = `-----BEGIN PUBLIC KEY-----
|
|
6
5
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Yt2RtNOdeKQxWMY0c84
|
|
7
6
|
ADpY1Jy58YWZhaEgP2A5tBwFUKgy/TH9gQLWZjQ3dQ/6XXO8qq0kluoYFqM7ZDRF
|
|
@@ -11,10 +10,10 @@ zRpQGOdqaLWe+ahHmtj6KtUZjm8o6lan4f/o08C6litizguZXuw2Nn/Kd9fFI1xF
|
|
|
11
10
|
IVNJYMy9jgGaOi71+LpGw+vIpwAawp/7IvULDppvY3DdX5nt05P1+jvVJXPxMKzD
|
|
12
11
|
TQIDAQAB
|
|
13
12
|
-----END PUBLIC KEY-----`;
|
|
14
|
-
const USER_ID_KEY = '
|
|
15
|
-
const FRONTEND_TOKEN_KEY = '
|
|
13
|
+
const USER_ID_KEY = 'mentraos_userId';
|
|
14
|
+
const FRONTEND_TOKEN_KEY = 'mentraos_frontendToken';
|
|
16
15
|
/**
|
|
17
|
-
* Verifies and parses a signed user token using the
|
|
16
|
+
* Verifies and parses a signed user token using the MentraOS Cloud public key
|
|
18
17
|
* @param signedUserToken - The JWT token to verify and parse
|
|
19
18
|
* @returns Promise that resolves to the parsed payload or null if invalid
|
|
20
19
|
*/
|
package/dist/lib/authCore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authCore.js","sourceRoot":"","sources":["../../src/lib/authCore.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"authCore.js","sourceRoot":"","sources":["../../src/lib/authCore.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAU,MAAM,WAAW,CAAC,CAAC,kCAAkC;AAErF,qFAAqF;AACrF,MAAM,qBAAqB,GAAG;;;;;;;;yBAQL,CAAC;AAE1B,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AAwBpD;;;;GAIG;AACH,KAAK,UAAU,mBAAmB,CAAC,eAAuB;IACxD,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAAW,CAAC;QAErE,4CAA4C;QAC5C,uDAAuD;QACvD,MAAM,OAAO,GAAG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a,EAAE,CAAC;QACvE,CAAC;aAAM,CAAC;YACN,oDAAoD;YACpD,eAAe,EAAE,CAAC;YAClB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,oDAAoD;IACpD,MAAM,YAAY,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACvD,MAAM,mBAAmB,GAAG,YAAY,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAErE,IAAI,YAAY,IAAI,mBAAmB,EAAE,CAAC;QACxC,oEAAoE;QACpE,gDAAgD;QAChD,4EAA4E;QAC5E,oEAAoE;QACpE,qEAAqE;QACrE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC;IACtE,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACjD,MAAM,aAAa,GAAG,YAAY,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/D,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,eAAe;IAC7B,YAAY,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACrC,YAAY,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MentraosAuthContextType } from './AuthProvider';
|
|
2
|
+
/**
|
|
3
|
+
* Custom hook to access the MentraOS authentication context.
|
|
4
|
+
*
|
|
5
|
+
* @returns {MentraosAuthContextType} The authentication context containing user state,
|
|
6
|
+
* loading status, error information, and authentication methods.
|
|
7
|
+
*
|
|
8
|
+
* @throws {Error} When used outside of an MentraosAuthProvider component.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { userId, isAuthenticated, logout, isLoading } = useMentraosAuth();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const useMentraosAuth: () => MentraosAuthContextType;
|
|
16
|
+
//# sourceMappingURL=useMentraosAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMentraosAuth.d.ts","sourceRoot":"","sources":["../src/useMentraosAuth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAE9E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,QAAO,uBAMlC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// react-sdk/src/useMentraosAuth.ts
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { MentraosAuthContext } from './AuthProvider';
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to access the MentraOS authentication context.
|
|
6
|
+
*
|
|
7
|
+
* @returns {MentraosAuthContextType} The authentication context containing user state,
|
|
8
|
+
* loading status, error information, and authentication methods.
|
|
9
|
+
*
|
|
10
|
+
* @throws {Error} When used outside of an MentraosAuthProvider component.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const { userId, isAuthenticated, logout, isLoading } = useMentraosAuth();
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const useMentraosAuth = () => {
|
|
18
|
+
const context = useContext(MentraosAuthContext);
|
|
19
|
+
if (context === undefined) {
|
|
20
|
+
throw new Error('useMentraosAuth must be used within an MentraosAuthProvider');
|
|
21
|
+
}
|
|
22
|
+
return context;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=useMentraosAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMentraosAuth.js","sourceRoot":"","sources":["../src/useMentraosAuth.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAA2B,MAAM,gBAAgB,CAAC;AAE9E;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAA4B,EAAE;IAC3D,MAAM,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAChD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
package/package.json
CHANGED
package/dist/useMentraAuth.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { MentraAuthContextType } from './AuthProvider';
|
|
2
|
-
/**
|
|
3
|
-
* Custom hook to access the Augmentos authentication context.
|
|
4
|
-
*
|
|
5
|
-
* @returns {MentraAuthContextType} The authentication context containing user state,
|
|
6
|
-
* loading status, error information, and authentication methods.
|
|
7
|
-
*
|
|
8
|
-
* @throws {Error} When used outside of an MentraAuthProvider component.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const { userId, isAuthenticated, logout, isLoading } = useMentraAuth();
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export declare const useMentraAuth: () => MentraAuthContextType;
|
|
16
|
-
//# sourceMappingURL=useMentraAuth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMentraAuth.d.ts","sourceRoot":"","sources":["../src/useMentraAuth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE1E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,QAAO,qBAMhC,CAAC"}
|
package/dist/useMentraAuth.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// augmentos-react/src/useMentraAuth.ts
|
|
2
|
-
import { useContext } from 'react';
|
|
3
|
-
import { MentraAuthContext } from './AuthProvider';
|
|
4
|
-
/**
|
|
5
|
-
* Custom hook to access the Augmentos authentication context.
|
|
6
|
-
*
|
|
7
|
-
* @returns {MentraAuthContextType} The authentication context containing user state,
|
|
8
|
-
* loading status, error information, and authentication methods.
|
|
9
|
-
*
|
|
10
|
-
* @throws {Error} When used outside of an MentraAuthProvider component.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* const { userId, isAuthenticated, logout, isLoading } = useMentraAuth();
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export const useMentraAuth = () => {
|
|
18
|
-
const context = useContext(MentraAuthContext);
|
|
19
|
-
if (context === undefined) {
|
|
20
|
-
throw new Error('useMentraAuth must be used within an MentraAuthProvider');
|
|
21
|
-
}
|
|
22
|
-
return context;
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=useMentraAuth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMentraAuth.js","sourceRoot":"","sources":["../src/useMentraAuth.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAyB,MAAM,gBAAgB,CAAC;AAE1E;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAA0B,EAAE;IACvD,MAAM,OAAO,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAC9C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|