Skip to content

Commit

Permalink
chore: add excludes props auth strategies in login and signup
Browse files Browse the repository at this point in the history
  • Loading branch information
pyadav committed Aug 2, 2023
1 parent d160f9f commit 3850468
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
16 changes: 12 additions & 4 deletions sdks/js/packages/core/react/components/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,34 @@ const styles = {
type SignedInProps = ComponentPropsWithRef<typeof Container> & {
logo?: React.ReactNode;
title?: string;
excludes?: string[];
};
export const SignedIn = ({
logo,
title = 'Login to Raypoint',
excludes = [],
...props
}: SignedInProps) => {
const { config } = useFrontier();
const { client, strategies = [] } = useFrontier();
const { config, client, strategies = [] } = useFrontier();

const clickHandler = useCallback(
async (name?: string) => {
if (!name) return;
if (!client) return;
await client.frontierServiceAuthenticate(name, { redirect: true });
const {
data: { endpoint = '' }
} = await client.frontierServiceAuthenticate(name);

window.location.href = endpoint;
},
[strategies]
);

const mailotp = strategies.find(s => s.name === 'mailotp');
const filteredOIDC = strategies.filter(s => s.name !== 'mailotp');
const filteredOIDC = strategies
.filter(s => s.name !== 'mailotp')
.filter(s => !excludes.includes(s.name ?? ''));

return (
<Container {...props}>
<Header logo={logo} title={title} />
Expand Down
14 changes: 9 additions & 5 deletions sdks/js/packages/core/react/components/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ const styles = {
type SignupProps = ComponentPropsWithRef<typeof Container> & {
logo?: React.ReactNode;
title?: string;
excludes?: string[];
};
export const Signup = ({
logo,
title = 'Create your account',
excludes = [],
...props
}: SignupProps) => {
const { config } = useFrontier();
Expand All @@ -30,16 +32,18 @@ export const Signup = ({
if (!client) return;

const {
data: { endpoint }
} = await client.frontierServiceAuthenticate(name, {
redirect: true
});
data: { endpoint = '' }
} = await client.frontierServiceAuthenticate(name);

window.location.href = endpoint;
},
[strategies]
);

const mailotp = strategies.find(s => s.name === 'mailotp');
const filteredOIDC = strategies.filter(s => s.name !== 'mailotp');
const filteredOIDC = strategies
.filter(s => s.name !== 'mailotp')
.filter(s => !excludes.includes(s.name ?? ''));

return (
<Container {...props}>
Expand Down
5 changes: 1 addition & 4 deletions sdks/js/packages/core/react/contexts/FrontierContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ export const FrontierContextProvider = ({
};

export const useFrontierClient = (options: FrontierClientOptions) => {
const frontierClient = React.useMemo(
() => Frontier.getInstance({ endpoint: options.endpoint }),
[]
);
const frontierClient = React.useMemo(() => Frontier.getInstance(options), []);

return { frontierClient };
};
Expand Down
6 changes: 3 additions & 3 deletions sdks/js/packages/core/react/frontier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export default class Frontier {
private constructor() {}

public static getInstance({ endpoint }: any): V1Beta1 {
if (!Frontier.instance) {
Frontier.instance = new FrontierClient({
if (!this.instance) {
this.instance = new FrontierClient({
baseUrl: endpoint,
baseApiParams: {
credentials: 'include'
}
});
}
return Frontier.instance;
return this.instance;
}
}

0 comments on commit 3850468

Please sign in to comment.