Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feature / release 2024 integrations support #19

Merged
merged 12 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -78,8 +78,15 @@ android/keystores/debug.keystore
lib/

example/.yarn
example/ios/CryptrReactNativeExample.xcodeproj/project.pbxproj

.env


coverage/

*.dt.ts

*.npmrc
.yarnrc
example/android/gradlew*
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -166,7 +166,7 @@ The return type is a <u>**key/value pair Object.**</u>
const { user } = useCryptr()

// ...
user()
user?.email
```

#### accessToken
@@ -315,3 +315,5 @@ Configuration change
Components/hooks

If you either used `signInWithDomain()` hook or `<CryptrGatewayButton/>` component without `domain` parameter, please use now `signIn` or `<SignInButton/>` accordingly

For easier usage of `user` hook this one changed from function `() => User | undefined`, now it's directly a `User | undefined`
92 changes: 0 additions & 92 deletions example/android/gradlew.bat

This file was deleted.

712 changes: 0 additions & 712 deletions example/ios/CryptrReactNativeExample.xcodeproj/project.pbxproj

This file was deleted.

12 changes: 5 additions & 7 deletions example/src/components/AuthenticatedView.tsx
Original file line number Diff line number Diff line change
@@ -44,20 +44,18 @@ const AuthenticatedView = () => {
<>
<Text style={styles.textAuthenticated}>You're logged in</Text>
<HorizontalDivider />
{user() && (
{user && (
<>
<TokenView title={user()!.org} value={`Issued at ${user()!.iat}`} />
<TokenView title={'Env'} value={user()!.env || '?'} />
<TokenView title={user!.org} value={`Issued at ${user!.iat}`} />
<TokenView title={'Env'} value={user!.env || '?'} />
<TokenView
title={'Identities'}
value={JSON.stringify(user()?.identities, null, 2)}
value={JSON.stringify(user?.identities, null, 2)}
/>
</>
)}
{accessToken && <TokenView title="Access token" value={accessToken} />}
{user() && (
<TokenView title="User" value={JSON.stringify(user(), null, 2)} />
)}
{user && <TokenView title="User" value={JSON.stringify(user, null, 2)} />}
<HorizontalDivider />
<LogOutButton
successCallback={logOutCallback}
7,641 changes: 1,654 additions & 5,987 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cryptr/cryptr-react-native",
"version": "1.0.0",
"version": "0.3.2",
"description": "React Native SDK for Cryptr Authentication",
"main": "lib/commonjs/index",
"module": "lib/module/index",
@@ -131,7 +131,8 @@
},
"eslintIgnore": [
"node_modules/",
"lib/"
"lib/",
"coverage/"
],
"prettier": {
"quoteProps": "consistent",
15 changes: 8 additions & 7 deletions src/Cryptr.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { NativeModules, Platform } from 'react-native';
// import { NativeModules, Platform } from 'react-native';
import { NativeModules } from 'react-native';
import type CryptrInterface from './utils/interfaces';

const LINKING_ERROR =
`The package '@cryptr/cryptr-react-native' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';
// const LINKING_ERROR =
// `The package '@cryptr/cryptr-react-native' doesn't seem to be linked. Make sure: \n\n` +
// Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
// '- You rebuilt the app after installing the package\n' +
// '- You are not using Expo Go\n';

const CryptrReactNative = NativeModules.CryptrReactNative
? NativeModules.CryptrReactNative
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
// throw new Error(LINKING_ERROR);
},
}
);
2 changes: 0 additions & 2 deletions src/session/CryptrContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createContext } from 'react';
import initialCryptrState from './initialCryptrState';
import type { CryptrConfig } from '../utils/interfaces';
import type { CryptrUser } from '../utils/types';

const error = (...args: any) => {
console.debug(args);
@@ -33,7 +32,6 @@ const initialContext = {
successCallback?: (data: any) => any,
errorCallback?: (data: any) => any
) => void,
user: error as unknown as () => CryptrUser | undefined,
};

const CryptrContext = createContext(initialContext);
10 changes: 3 additions & 7 deletions src/session/CryptrProvider.tsx
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@ import {
import Jwt from '../utils/jwt';
import Cryptr from '../Cryptr';
import { DeviceEventEmitter } from 'react-native';
import type { CryptrUser } from '../utils/types';

const CryptrProvider: React.FC<ProviderProps> = ({
children,
@@ -79,6 +78,7 @@ const CryptrProvider: React.FC<ProviderProps> = ({
DeviceEventEmitter.addListener('onNavigationEvent', (event) => {
handleSecuredViewEvent(event);
});
setUnloading();
refreshTokens((data: any) => {
const { error } = data;
error && setError(error);
@@ -302,7 +302,8 @@ const CryptrProvider: React.FC<ProviderProps> = ({
errorCallback && errorCallback(error);
});
} else {
console.warn('no refreh found');
setUnloading();
console.warn('no refresh found');
}
},
(error: any) => {
@@ -325,17 +326,12 @@ const CryptrProvider: React.FC<ProviderProps> = ({
return jsonApiRequest(refreshTokenUrl(config), body);
};

const getUser = (): CryptrUser | undefined => {
return state.idToken ? (Jwt.body(state.idToken) as CryptrUser) : undefined;
};

return (
<CryptrContext.Provider
data-testid="CryptrProvider"
value={{
...state,
config: () => config,
user: () => getUser(),
logOut: (
successCallback?: (data: any) => any,
errorCallback?: (data: any) => any
11 changes: 9 additions & 2 deletions src/session/CryptrReducer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { CryptrReducerActionKind } from '../utils/enums';
import type { CryptrAction, CryptrState } from '../utils/interfaces';
import Jwt from '../utils/jwt';
import type { CryptrUser } from '../utils/types';

const CryptrReducer = (state: CryptrState, action: CryptrAction) => {
switch (action.type) {
@@ -18,11 +20,15 @@ const CryptrReducer = (state: CryptrState, action: CryptrAction) => {
error_description: undefined,
};
case CryptrReducerActionKind.AUTHENTICATED:
let accessToken = action.payload && action.payload.access_token;
let idToken = action.payload && action.payload.id_token;
let userVal = idToken ? (Jwt.body(idToken) as CryptrUser) : undefined;
return {
...state,
isAuthenticated: true,
accessToken: action.payload && action.payload.access_token,
idToken: action.payload && action.payload.id_token,
accessToken: accessToken,
idToken: idToken,
user: userVal,
isLoading: false,
};
case CryptrReducerActionKind.UNAUTHENTICATED:
@@ -33,6 +39,7 @@ const CryptrReducer = (state: CryptrState, action: CryptrAction) => {
error_description: action.payload && action.payload.error_description,
accessToken: undefined,
idToken: undefined,
user: undefined,
isLoading: false,
};
case CryptrReducerActionKind.ERROR:
1 change: 1 addition & 0 deletions src/session/initialCryptrState.tsx
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ const initialCryptrState: CryptrState = {
isAuthenticated: false,
accessToken: undefined,
idToken: undefined,
user: undefined,
};

export default initialCryptrState;
2 changes: 2 additions & 0 deletions src/utils/interfaces.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ReactNode } from 'react';
import type { CryptrReducerActionKind } from './enums';
import type { CryptrUser } from './types';

export interface CryptrConfig {
accountDomain: string;
@@ -46,6 +47,7 @@ export interface CryptrState {
isLoading: boolean;
accessToken?: string;
idToken?: string;
user?: CryptrUser;
error?: any;
error_description?: string;
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
"skipLibCheck": true,
"strict": true,
"target": "esnext",
"verbatimModuleSyntax": true
"verbatimModuleSyntax": true,
"declaration": true
}
}
20,330 changes: 7,576 additions & 12,754 deletions yarn.lock

Large diffs are not rendered by default.