Skip to content

Commit 339416f

Browse files
committed
feat: better login
1 parent 241c41c commit 339416f

File tree

2 files changed

+53
-65
lines changed

2 files changed

+53
-65
lines changed

apps/frontend/src/components/auth/providers/farcaster.provider.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
import { useCallback } from 'react';
1+
import { FC, useCallback } from 'react';
22
import interClass from '@gitroom/react/helpers/inter.font';
33
import { useVariables } from '@gitroom/react/helpers/variable.context';
44
import { NeynarContextProvider, Theme, useNeynarContext } from '@neynar/react';
55
import { NeynarAuthButton } from '@gitroom/frontend/components/auth/nayner.auth.button';
6-
import { useRouter } from 'next/navigation';
76

87
export const FarcasterProvider = () => {
9-
const { neynarClientId } = useVariables();
10-
118
const gotoLogin = useCallback(async (code: string) => {
129
window.location.href = `/auth?provider=FARCASTER&code=${code}`;
1310
}, []);
1411

12+
return (
13+
<ButtonCaster login={gotoLogin} />
14+
);
15+
};
16+
17+
export const ButtonCaster: FC<{ login: (code: string) => void }> = (props) => {
18+
const { login } = props;
19+
const { neynarClientId } = useVariables();
1520
return (
1621
<NeynarContextProvider
1722
settings={{
1823
clientId: neynarClientId,
1924
defaultTheme: Theme.Dark,
2025
}}
2126
>
22-
<NeynarAuthButton onLogin={gotoLogin}>
27+
<NeynarAuthButton onLogin={login}>
2328
<div
2429
className={`cursor-pointer bg-[#855ECD] h-[44px] rounded-[4px] flex justify-center items-center text-white ${interClass} gap-[4px]`}
2530
>

apps/frontend/src/components/launches/web3/providers/wrapcaster.provider.tsx

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,59 @@ import { useVariables } from '@gitroom/react/helpers/variable.context';
66
import { TopTitle } from '@gitroom/frontend/components/launches/helpers/top.title.component';
77
import { useModals } from '@mantine/modals';
88
import { LoadingComponent } from '@gitroom/frontend/components/layout/loading';
9-
import { NeynarAuthButton, NeynarContextProvider, Theme, useNeynarContext } from '@neynar/react';
9+
import {
10+
NeynarAuthButton,
11+
NeynarContextProvider,
12+
Theme,
13+
useNeynarContext,
14+
} from '@neynar/react';
1015
import { INeynarAuthenticatedUser } from '@neynar/react/dist/types/common';
16+
import { ButtonCaster } from '@gitroom/frontend/components/auth/providers/farcaster.provider';
1117

1218
export const WrapcasterProvider: FC<Web3ProviderInterface> = (props) => {
13-
const [id, state] = props.nonce.split('||');
19+
const [_, state] = props.nonce.split('||');
1420
const modal = useModals();
1521
const [hide, setHide] = useState(false);
1622

17-
const auth = useCallback((params: { user: INeynarAuthenticatedUser }) => {
23+
const auth = useCallback((code: string) => {
1824
setHide(true);
19-
return props.onComplete(Buffer.from(JSON.stringify(params.user)).toString('base64'), state);
20-
}, []);
25+
return props.onComplete(code, state);
26+
}, [state]);
2127

2228
return (
23-
<NeynarContextProvider
24-
settings={{
25-
clientId: id || '',
26-
defaultTheme: Theme.Dark,
27-
// eventsCallbacks: {
28-
// onAuthSuccess: (params: { user: INeynarAuthenticatedUser }) => {
29-
// auth(params);
30-
// },
31-
// },
32-
}}
33-
>
34-
<div className="rounded-[4px] border border-customColor6 bg-sixth px-[16px] pb-[16px] relative w-full">
35-
<TopTitle title={`Add Wrapcast`} />
36-
<button
37-
className="outline-none absolute right-[20px] top-[20px] mantine-UnstyledButton-root mantine-ActionIcon-root hover:bg-tableBorder cursor-pointer mantine-Modal-close mantine-1dcetaa"
38-
type="button"
39-
onClick={() => modal.closeAll()}
29+
<div className="rounded-[4px] border border-customColor6 bg-sixth px-[16px] pb-[16px] relative w-full">
30+
<TopTitle title={`Add Wrapcast`} />
31+
<button
32+
className="outline-none absolute right-[20px] top-[20px] mantine-UnstyledButton-root mantine-ActionIcon-root hover:bg-tableBorder cursor-pointer mantine-Modal-close mantine-1dcetaa"
33+
type="button"
34+
onClick={() => modal.closeAll()}
35+
>
36+
<svg
37+
viewBox="0 0 15 15"
38+
fill="none"
39+
xmlns="http://www.w3.org/2000/svg"
40+
width="16"
41+
height="16"
4042
>
41-
<svg
42-
viewBox="0 0 15 15"
43-
fill="none"
44-
xmlns="http://www.w3.org/2000/svg"
45-
width="16"
46-
height="16"
47-
>
48-
<path
49-
d="M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z"
50-
fill="currentColor"
51-
fillRule="evenodd"
52-
clipRule="evenodd"
53-
></path>
54-
</svg>
55-
</button>
56-
<div className="justify-center items-center flex">
57-
{hide ? (
58-
<div className="justify-center items-center flex -mt-[90px]">
59-
<LoadingComponent width={100} height={100} />
60-
</div>
61-
) : (
62-
<div className="justify-center items-center flex py-[20px]">
63-
<Logged onSuccess={auth} />
64-
<NeynarAuthButton className="right-4 top-4" />
65-
</div>
66-
)}
67-
</div>
43+
<path
44+
d="M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z"
45+
fill="currentColor"
46+
fillRule="evenodd"
47+
clipRule="evenodd"
48+
></path>
49+
</svg>
50+
</button>
51+
<div className="justify-center items-center flex">
52+
{hide ? (
53+
<div className="justify-center items-center flex -mt-[90px]">
54+
<LoadingComponent width={100} height={100} />
55+
</div>
56+
) : (
57+
<div className="justify-center items-center py-[20px] flex-col w-[500px]">
58+
<ButtonCaster login={auth} />
59+
</div>
60+
)}
6861
</div>
69-
</NeynarContextProvider>
62+
</div>
7063
);
7164
};
72-
73-
export const Logged: FC<{onSuccess: (params: {user: INeynarAuthenticatedUser}) => void}> = (props) => {
74-
const context = useNeynarContext();
75-
useEffect(() => {
76-
if (context.isAuthenticated && context.user) {
77-
props.onSuccess({ user: context.user });
78-
}
79-
}, [context.isAuthenticated]);
80-
return null;
81-
}

0 commit comments

Comments
 (0)