Skip to content

Commit

Permalink
feat: support multi accesstokens android (#46)
Browse files Browse the repository at this point in the history
* feat: change native android to support multi access token

* feat: add types to RN token methods

* docs: update readme

* chore: update tickets sdk [android]

---------

Co-authored-by: Daniel <daniel.olugbade@ticketmaster.co.uk>
  • Loading branch information
joe-goodall-ticketmaster and DanielOS7-TM authored Oct 11, 2024
1 parent 2c72ac4 commit efa7525
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ try {
{isLoggedIn && <Text>You are logged in<Text/>}
```

`getToken` and `refreshToken` return different data types per platform. iOS returns a `string` and Android returns an object. See Android object type below:

```typescript
type AuthSource = {
hostAccessToken?: string;
archticsAccessToken?: string;
mfxAccessToken?: string;
sportXRAccessToken?: string;
};
```


The `login()` method from the `useIgnite` hook accepts an object with properties `onLogin` and `skipUpdate`:

- `onLogin` - a callback that fires after successful authentication
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.10.1'

implementation 'com.ticketmaster.accounts:authentication:3.9.0_jdk15to18_bouncycastle-SNAPSHOT'
implementation 'com.ticketmaster.tickets:tickets:3.8.0'
implementation 'com.ticketmaster.tickets:tickets:3.8.3'
implementation 'com.ticketmaster.tickets:secure-entry:1.2.10'
implementation 'com.ticketmaster.retail:purchase:3.2.0'
implementation 'com.ticketmaster.retail:prepurchase:3.2.0'
Expand Down
26 changes: 13 additions & 13 deletions android/src/main/java/com/ticketmasterignite/AccountsSDKModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,21 @@ class AccountsSDKModule(reactContext: ReactApplicationContext) :
val tokenRefreshedParams: WritableMap = Arguments.createMap().apply {
putString("accountsSdkTokenRefreshed", "accountsSdkTokenRefreshed")
}
val combinedTokens: WritableMap = Arguments.createMap()
if (!resHostAccessToken.isNullOrEmpty()) {
GlobalEventEmitter.sendEvent("igniteAnalytics", tokenRefreshedParams)
promise.resolve(resHostAccessToken)
} else if (!resArchticsAccessToken.isNullOrEmpty()) {
GlobalEventEmitter.sendEvent("igniteAnalytics", tokenRefreshedParams)
promise.resolve(resArchticsAccessToken)
} else if (!resMfxAccessToken.isNullOrEmpty()) {
GlobalEventEmitter.sendEvent("igniteAnalytics", tokenRefreshedParams)
promise.resolve(resMfxAccessToken)
} else if (!resSportXRAccessToken.isNullOrEmpty()) {
GlobalEventEmitter.sendEvent("igniteAnalytics", tokenRefreshedParams)
promise.resolve(resSportXRAccessToken)
}else {
promise.resolve(null)
combinedTokens.putString("hostAccessToken", resHostAccessToken)
}
if (!resArchticsAccessToken.isNullOrEmpty()) {
combinedTokens.putString("archticsAccessToken", resArchticsAccessToken)
}
if (!resMfxAccessToken.isNullOrEmpty()) {
combinedTokens.putString("mfxAccessToken", resMfxAccessToken)
}
if (!resSportXRAccessToken.isNullOrEmpty()) {
combinedTokens.putString("sportXRAccessToken", resSportXRAccessToken)
}
GlobalEventEmitter.sendEvent("igniteAnalytics", tokenRefreshedParams)
promise.resolve(combinedTokens)
} catch (e: Exception) {
promise.reject("Accounts SDK refreshToken Error: ", e)
}
Expand Down
19 changes: 15 additions & 4 deletions src/IgniteProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ type IgniteContextType = {
login: (LoginParams?: LoginParams) => Promise<void>;
logout: (LogoutParams?: LogoutParams) => Promise<void>;
getIsLoggedIn: () => Promise<boolean>;
getToken: () => Promise<string | null>;
getToken: () => Promise<string | AuthSource | null>;
getMemberInfo: () => Promise<Record<string, any> | null>;
refreshToken: () => Promise<string | null>;
refreshToken: () => Promise<string | AuthSource | null>;
authState: AuthStateParams;
isLoggingIn: boolean;
};

type Region = 'US' | 'UK';

type AuthSource = {
hostAccessToken?: string;
archticsAccessToken?: string;
mfxAccessToken?: string;
sportXRAccessToken?: string;
};

export const IgniteContext = createContext<IgniteContextType>({
login: async () => {},
logout: async () => {},
Expand Down Expand Up @@ -225,7 +232,9 @@ export const IgniteProvider: React.FC<IgniteProviderProps> = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const getToken = useCallback(async (): Promise<string | null> => {
const getToken = useCallback(async (): Promise<
string | AuthSource | null
> => {
let accessToken;
try {
if (Platform.OS === 'ios') {
Expand Down Expand Up @@ -268,7 +277,9 @@ export const IgniteProvider: React.FC<IgniteProviderProps> = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const refreshToken = useCallback(async (): Promise<string | null> => {
const refreshToken = useCallback(async (): Promise<
string | AuthSource | null
> => {
try {
const result = await AccountsSDK.refreshToken();
console.log('Accounts SDK refresh token:', result);
Expand Down

0 comments on commit efa7525

Please sign in to comment.