@atls/react-native-kratos 0.0.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+
2
+
3
+ ## 0.0.1 (2025-01-22)
4
+
5
+
6
+ ### Features
7
+
8
+
9
+ * **ory:** init ([#2](https://github.com/atls/react-native/issues/2)) ([aca4a51](https://github.com/atls/react-native/commit/aca4a5185ff3c36b16ec830c3952e22f1f9925dc))
10
+
11
+
@@ -0,0 +1,2 @@
1
+ export * from './react-native-login.flow';
2
+ export * from './react-native-registration.flow';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./react-native-login.flow"), exports);
18
+ __exportStar(require("./react-native-registration.flow"), exports);
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ReactElement } from 'react';
3
+ export interface ReactNativeLoginFlowProps {
4
+ route: {
5
+ params?: {
6
+ aal?: 'aal1' | 'aal2';
7
+ refresh?: boolean;
8
+ };
9
+ };
10
+ children: ReactNode;
11
+ }
12
+ export declare const ReactNativeLoginFlow: ({ children, route, }: ReactNativeLoginFlowProps) => ReactElement;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ReactNativeLoginFlow = void 0;
7
+ const react_kratos_1 = require("@atls/react-kratos");
8
+ const expo_auth_session_1 = require("expo-auth-session");
9
+ const react_1 = __importDefault(require("react"));
10
+ const hooks_1 = require("../hooks");
11
+ const ReactNativeLoginFlow = ({ children, route, }) => {
12
+ const { sessionToken, setSession } = (0, hooks_1.useAuth)();
13
+ return (react_1.default.createElement(react_kratos_1.LoginNativeFlow, { aal: route.params?.aal, refresh: route.params?.refresh, sessionToken: sessionToken, returnTo: (0, expo_auth_session_1.makeRedirectUri)({
14
+ preferLocalhost: true,
15
+ path: '/Callback',
16
+ }), onSession: setSession }, children));
17
+ };
18
+ exports.ReactNativeLoginFlow = ReactNativeLoginFlow;
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ReactElement } from 'react';
3
+ export interface ReactNativeRegistrationFlowProps {
4
+ children: ReactNode;
5
+ }
6
+ export declare const ReactNativeRegistrationFlow: ({ children, }: ReactNativeRegistrationFlowProps) => ReactElement;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ReactNativeRegistrationFlow = void 0;
7
+ const react_kratos_1 = require("@atls/react-kratos");
8
+ const react_1 = __importDefault(require("react"));
9
+ const hooks_1 = require("../hooks");
10
+ const ReactNativeRegistrationFlow = ({ children, }) => {
11
+ const { setSession } = (0, hooks_1.useAuth)();
12
+ return react_1.default.createElement(react_kratos_1.RegistrationNativeFlow, { onSession: setSession }, children);
13
+ };
14
+ exports.ReactNativeRegistrationFlow = ReactNativeRegistrationFlow;
@@ -0,0 +1 @@
1
+ export * from './use-auth.hook';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./use-auth.hook"), exports);
@@ -0,0 +1,2 @@
1
+ import type { ContextAuth } from '../providers';
2
+ export declare const useAuth: () => ContextAuth;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAuth = void 0;
4
+ const react_1 = require("react");
5
+ const providers_1 = require("../providers");
6
+ const useAuth = () => {
7
+ const auth = (0, react_1.useContext)(providers_1.AuthContext);
8
+ if (!auth) {
9
+ throw new Error('Missing <AuthProvider>');
10
+ }
11
+ return auth;
12
+ };
13
+ exports.useAuth = useAuth;
@@ -0,0 +1,4 @@
1
+ export * from '@atls/react-kratos';
2
+ export * from './providers';
3
+ export * from './flows';
4
+ export * from './hooks';
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("@atls/react-kratos"), exports);
18
+ __exportStar(require("./providers"), exports);
19
+ __exportStar(require("./flows"), exports);
20
+ __exportStar(require("./hooks"), exports);
@@ -0,0 +1,20 @@
1
+ import type { Session } from '@atls/react-kratos';
2
+ import type { ReactElement } from 'react';
3
+ import type { ReactNode } from 'react';
4
+ import React from 'react';
5
+ export type SessionContext = {
6
+ sessionToken?: string;
7
+ session: Session;
8
+ } | undefined;
9
+ export interface ContextAuth {
10
+ session?: Session;
11
+ sessionToken?: string;
12
+ isAuthenticated: boolean;
13
+ setSession: (session: SessionContext) => Promise<void>;
14
+ }
15
+ export declare const AuthContext: React.Context<ContextAuth>;
16
+ interface AuthProviderProps {
17
+ children: ReactNode;
18
+ }
19
+ export declare const AuthProvider: ({ children }: AuthProviderProps) => ReactElement | null;
20
+ export {};
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.AuthProvider = exports.AuthContext = void 0;
30
+ const react_kratos_1 = require("@atls/react-kratos");
31
+ const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
32
+ const SecureStore = __importStar(require("expo-secure-store"));
33
+ const react_native_1 = require("react-native");
34
+ const react_1 = require("react");
35
+ const react_2 = require("react");
36
+ const react_3 = require("react");
37
+ const react_4 = require("react");
38
+ const react_5 = __importDefault(require("react"));
39
+ const USER_SESSION_NAME = 'user_session';
40
+ exports.AuthContext = (0, react_1.createContext)({
41
+ isAuthenticated: false,
42
+ setSession: async () => Promise.resolve(),
43
+ });
44
+ const AuthProvider = ({ children }) => {
45
+ const [sessionContext, setSessionContext] = (0, react_4.useState)(undefined);
46
+ const [initialized, setInitialized] = (0, react_4.useState)(false);
47
+ const sdk = (0, react_kratos_1.useSdk)();
48
+ const setSession = (0, react_2.useCallback)(async (session) => {
49
+ if (react_native_1.Platform.OS !== 'web') {
50
+ await SecureStore.setItemAsync(USER_SESSION_NAME, JSON.stringify(session));
51
+ }
52
+ else {
53
+ await async_storage_1.default.setItem(USER_SESSION_NAME, JSON.stringify(session));
54
+ }
55
+ setSessionContext(session);
56
+ }, [setSessionContext]);
57
+ (0, react_3.useEffect)(() => {
58
+ const getAuthenticatedSession = async () => {
59
+ const userSession = react_native_1.Platform.OS !== 'web'
60
+ ? await SecureStore.getItemAsync(USER_SESSION_NAME)
61
+ : await async_storage_1.default.getItem(USER_SESSION_NAME);
62
+ const auth = userSession ? JSON.parse(userSession) : undefined;
63
+ if (auth?.sessionToken) {
64
+ try {
65
+ const { data: session } = await sdk.toSession({ xSessionToken: auth.sessionToken });
66
+ setSessionContext({ session, sessionToken: auth.sessionToken });
67
+ }
68
+ catch (error) {
69
+ console.log(error);
70
+ setSessionContext(undefined);
71
+ }
72
+ }
73
+ setInitialized(true);
74
+ };
75
+ getAuthenticatedSession();
76
+ }, [sdk]);
77
+ if (!initialized) {
78
+ return null;
79
+ }
80
+ return (react_5.default.createElement(exports.AuthContext.Provider, { value: {
81
+ session: sessionContext?.session,
82
+ sessionToken: sessionContext?.sessionToken,
83
+ isAuthenticated: Boolean(sessionContext?.sessionToken),
84
+ setSession,
85
+ } }, children));
86
+ };
87
+ exports.AuthProvider = AuthProvider;
@@ -0,0 +1 @@
1
+ export * from './auth.provider';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./auth.provider"), exports);
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@atls/react-native-kratos",
3
+ "version": "0.0.1",
4
+ "license": "BSD-3-Clause",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "build": "yarn library build",
11
+ "prepack": "yarn run build",
12
+ "postpack": "rm -rf dist"
13
+ },
14
+ "dependencies": {
15
+ "@atls/react-kratos": "0.0.2"
16
+ },
17
+ "devDependencies": {
18
+ "@react-native-async-storage/async-storage": "^1.21.0",
19
+ "@types/react": "^18.2.45",
20
+ "@types/react-dom": "^18.2.18",
21
+ "expo-auth-session": "^5.4.0",
22
+ "expo-secure-store": "^12.8.1",
23
+ "react": "^18.2.0",
24
+ "react-dom": "^18.2.0",
25
+ "react-native": "^0.73.1"
26
+ },
27
+ "peerDependencies": {
28
+ "@react-native-async-storage/async-storage": "^1",
29
+ "expo-auth-session": "^5",
30
+ "expo-secure-store": "^12",
31
+ "react": "^18.0.0",
32
+ "react-native": "^0.73.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "main": "dist/index.js",
37
+ "typings": "dist/index.d.ts"
38
+ },
39
+ "typecheckSkipLibCheck": true,
40
+ "typings": "dist/index.d.ts"
41
+ }