Skip to content

Commit

Permalink
chore: Remove Identity UI (#2238)
Browse files Browse the repository at this point in the history
* chore: Remove identity from UI

* chore: linting

* chore: Remove the sign in but keep the identity validation

* chore: Cleanup
  • Loading branch information
jimhunty committed Jul 18, 2023
1 parent 1d4a406 commit ce0d31e
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 721 deletions.
5 changes: 0 additions & 5 deletions projects/Mallard/src/AppNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { ArticleWrapper } from './navigation/navigators/article';
import { EditionsMenuScreen } from './screens/editions-menu-screen';
import { ExternalSubscriptionScreen } from './screens/external-subscription';
import { HomeScreen } from './screens/home-screen';
import { AuthSwitcherScreen } from './screens/identity-login-screen';
import { InAppPurchaseScreen } from './screens/in-app-purchase-screen';
import { IssueScreen } from './screens/issue-screen';
import { LightboxScreen } from './screens/lightbox';
Expand Down Expand Up @@ -358,10 +357,6 @@ const SettingsStack = () => {
name={RouteNames.WeatherGeolocationConsent}
component={WeatherGeolocationConsentScreen}
/>
<Settings.Screen
name={RouteNames.SignIn}
component={AuthSwitcherScreen}
/>
<Settings.Screen name={RouteNames.Help} component={HelpScreen} />
<Settings.Screen name={RouteNames.FAQ} component={FAQScreen} />
<Settings.Screen name={RouteNames.DevZone} component={DevZone} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@ import {
userAccessTokenKeychain,
userDataCache,
} from 'src/helpers/storage';
import { isIdentityEnabled } from 'src/hooks/use-is-identity-enbaled';
import { canViewEdition } from '../helpers';
import { Authorizer } from '../lib/Authorizer';
import type { AuthResult } from '../lib/Result';
import { flat, InvalidResult, ValidResult } from '../lib/Result';
import type { User } from '../services/identity';
import {
fetchAuth,
fetchMembershipToken,
fetchUserDetails,
} from '../services/identity';
import { InvalidResult } from '../lib/Result';
import type { MembersDataAPIResponse } from '../services/membership';
import { fetchMembershipData } from '../services/membership';

type BasicCreds = {
email: string;
Expand Down Expand Up @@ -44,31 +35,47 @@ export type AuthParams =
| AppleCreds
| AppleOauthCreds;

export type AuthType = 'apple' | 'google' | 'email' | 'apple-oauth' | 'unknown';
type AuthType = 'apple' | 'google' | 'email' | 'apple-oauth' | 'unknown';

interface User {
id: string;
dates: {
accountCreatedDate: string;
};
adData: {};
consents: Array<{
id: string;
actor: string;
version: number;
consented: boolean;
timestamp: string;
privacyPolicyVersion: number;
}>;
userGroups: Array<{
path: string;
packageCode: string;
}>;
socialLinks: Array<{
network: string;
socialId: string;
}>;
publicFields: {
displayName: string;
};
statusFields: {
hasRepermissioned: boolean;
userEmailValidated: boolean;
allowThirdPartyProfiling: boolean;
};
primaryEmailAddress: string;
hasPassword: boolean;
}

export type IdentityAuthData = {
userDetails: User;
membershipData: MembersDataAPIResponse;
};

const authWithTokens = async (
utoken: string,
mtoken: string,
): Promise<AuthResult<IdentityAuthData>> => {
const [userDetailsResult, membershipDataResult] = await Promise.all([
fetchUserDetails(utoken),
fetchMembershipData(mtoken),
]);
return flat(userDetailsResult, (userDetails) =>
flat(membershipDataResult, async (membershipData) =>
ValidResult({
userDetails,
membershipData,
}),
),
);
};

export const getUserName = (authType: AuthType, params: AuthParams): string => {
const unknown = 'unknown';
switch (authType) {
Expand Down Expand Up @@ -101,34 +108,11 @@ export default new Authorizer({
membershipAccessTokenKeychain,
legacyUserAccessTokenKeychain,
] as const,
auth: async ([params]: [AuthParams], [utc, mtc]) => {
const authType = detectAuthType(params);
const username = getUserName(authType, params);
const utokenResult = await fetchAuth<string>(params, authType);

return flat(utokenResult, async (utoken) => {
utc.set({ username, token: utoken });
const mtokenResult = await fetchMembershipToken(utoken);

return flat(mtokenResult, (mtoken) => {
mtc.set({ username, token: mtoken });
return authWithTokens(utoken, mtoken);
});
});
auth: async () => {
return InvalidResult();
},
authWithCachedCredentials: async ([utc, mtc, lutc]) => {
if (isIdentityEnabled) {
const [nutoken, lutoken, mtoken] = await Promise.all([
utc.get(),
lutc.get(),
mtc.get(),
]);
const utoken = nutoken ?? lutoken;
if (!utoken || !mtoken) return InvalidResult();
return authWithTokens(utoken.password, mtoken.password);
} else {
return InvalidResult();
}
authWithCachedCredentials: async () => {
return InvalidResult();
},
checkUserHasAccess: canViewEdition,
});
52 changes: 0 additions & 52 deletions projects/Mallard/src/authentication/services/apple-oauth.ts

This file was deleted.

52 changes: 0 additions & 52 deletions projects/Mallard/src/authentication/services/apple.ts

This file was deleted.

89 changes: 0 additions & 89 deletions projects/Mallard/src/authentication/services/google.ts

This file was deleted.

Loading

0 comments on commit ce0d31e

Please sign in to comment.