-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from farcasterxyz/nickcherry/mobile-auth
Remove Next Auth
- Loading branch information
Showing
20 changed files
with
317 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,44 @@ | ||
import { useAuth } from '@mobile/contexts/AuthProvider'; | ||
import { FeedScreen } from '@mobile/screens/FeedScreen'; | ||
import { LandingScreen } from '@mobile/screens/LandingScreen'; | ||
import { ProfileScreen } from '@mobile/screens/ProfileScreen'; | ||
import { RootParamList } from '@mobile/types/navigation'; | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
|
||
const Stack = createNativeStackNavigator<RootParamList>(); | ||
|
||
export function Navigator() { | ||
const { isSignedIn } = useAuth(); | ||
|
||
return ( | ||
<Stack.Navigator> | ||
<Stack.Screen | ||
name="Feed" | ||
component={FeedScreen} | ||
options={{ headerShown: false }} | ||
/> | ||
<Stack.Screen | ||
name="Profile" | ||
component={ProfileScreen} | ||
options={({ route }) => { | ||
const { displayName } = route.params as RootParamList['Profile']; | ||
return { | ||
headerTitle: displayName, | ||
}; | ||
}} | ||
/> | ||
{isSignedIn ? ( | ||
<> | ||
<Stack.Screen | ||
name="Feed" | ||
component={FeedScreen} | ||
options={{ headerShown: false }} | ||
/> | ||
<Stack.Screen | ||
name="Profile" | ||
component={ProfileScreen} | ||
options={({ route }) => { | ||
const { displayName } = route.params as RootParamList['Profile']; | ||
return { | ||
headerTitle: displayName, | ||
}; | ||
}} | ||
/> | ||
</> | ||
) : ( | ||
<> | ||
<Stack.Screen | ||
name="Landing" | ||
component={LandingScreen} | ||
options={{ headerShown: false }} | ||
/> | ||
</> | ||
)} | ||
</Stack.Navigator> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { AuthKitProvider, useSignIn } from '@farcaster/auth-kit'; | ||
import { | ||
createContext, | ||
ReactNode, | ||
useCallback, | ||
useContext, | ||
useState, | ||
} from 'react'; | ||
import { Linking } from 'react-native'; | ||
|
||
const AuthContext = createContext<{ | ||
isSignedIn: boolean; | ||
signIn: () => Promise<void>; | ||
token: string | undefined; | ||
}>({ | ||
isSignedIn: false, | ||
signIn: async () => { | ||
throw new Error( | ||
'You need to add an AuthProvider to the top of your React tree.', | ||
); | ||
}, | ||
token: undefined, | ||
}); | ||
|
||
type AuthProviderProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
function AuthProviderContent({ children }: AuthProviderProps) { | ||
const [token, setToken] = useState<string>(); | ||
|
||
const { | ||
connect, | ||
url, | ||
signIn: authKitSignIn, | ||
} = useSignIn({ | ||
onSuccess: (res) => { | ||
// setToken(res); | ||
}, | ||
}); | ||
const signIn = useCallback(async () => { | ||
// if (url) { | ||
await connect(); | ||
await authKitSignIn(); // Starts polling | ||
Linking.openURL(url); | ||
// } | ||
}, [authKitSignIn, connect, url]); | ||
|
||
return ( | ||
<AuthContext.Provider value={{ isSignedIn: !!token, signIn, token }}> | ||
{children} | ||
</AuthContext.Provider> | ||
); | ||
} | ||
|
||
export function AuthProvider(props: AuthProviderProps) { | ||
return ( | ||
<AuthKitProvider | ||
config={{ | ||
relay: 'https://relay.farcaster.xyz', | ||
rpcUrl: 'https://mainnet.optimism.io', | ||
siweUri: 'http://localhost:3000', | ||
domain: 'localhost:3000', | ||
}} | ||
> | ||
<AuthProviderContent {...props} /> | ||
</AuthKitProvider> | ||
); | ||
} | ||
|
||
export function useAuth() { | ||
return useContext(AuthContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Loader } from '@mobile/components/loader/Loader'; | ||
import { useAuth } from '@mobile/contexts/AuthProvider'; | ||
import { buildScreen } from '@mobile/utils/buildScreen'; | ||
import { useState } from 'react'; | ||
import { Pressable, Text, View } from 'react-native'; | ||
|
||
export const LandingScreen = buildScreen(() => { | ||
const { signIn } = useAuth(); | ||
const [isSigningIn, setIsSigningIn] = useState(false); | ||
|
||
return ( | ||
<View className="flex-1 items-center justify-center"> | ||
<Pressable | ||
onPress={async () => { | ||
setIsSigningIn(true); | ||
|
||
try { | ||
await signIn(); | ||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
setIsSigningIn(false); | ||
} | ||
}} | ||
> | ||
<View className="bg-fc-purple min-h-[60px] min-w-[120px] flex-row items-center justify-center rounded-lg p-4"> | ||
{isSigningIn ? ( | ||
<Loader /> | ||
) : ( | ||
<Text className="text-lg font-bold text-white">Login</Text> | ||
)} | ||
</View> | ||
</Pressable> | ||
</View> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
module.exports = { | ||
extends: ["next/core-web-vitals", "plugin:tailwindcss/recommended"], | ||
plugins: ["simple-import-sort", "unused-imports"], | ||
extends: ['next/core-web-vitals', 'plugin:tailwindcss/recommended'], | ||
plugins: ['simple-import-sort', 'unused-imports'], | ||
rules: { | ||
"@next/next/no-img-element": "off", | ||
"jsx-a11y/alt-text": "off", | ||
"no-duplicate-imports": "error", | ||
"simple-import-sort/exports": "error", | ||
"simple-import-sort/imports": "error", | ||
"tailwindcss/no-custom-classname": "error", | ||
"unused-imports/no-unused-imports": "error", | ||
'@next/next/no-img-element': 'off', | ||
'jsx-a11y/alt-text': 'off', | ||
'no-duplicate-imports': 'error', | ||
'simple-import-sort/exports': 'error', | ||
'simple-import-sort/imports': 'error', | ||
'tailwindcss/no-custom-classname': 'off', | ||
'unused-imports/no-unused-imports': 'error', | ||
}, | ||
}; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createAppClient, viemConnector } from '@farcaster/auth-kit'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
type RequestBody = { | ||
message: string; | ||
signature: `0x${string}`; | ||
nonce: string; | ||
}; | ||
|
||
export async function POST(request: Request) { | ||
const { message, signature, nonce }: RequestBody = await request.json(); | ||
|
||
const appClient = createAppClient({ | ||
ethereum: viemConnector(), | ||
}); | ||
|
||
const verifyResult = await appClient.verifySignInMessage({ | ||
domain: 'localhost:3000', | ||
message, | ||
nonce, | ||
signature, | ||
}); | ||
|
||
if (!verifyResult.success) { | ||
return NextResponse.json(verifyResult.error || 'Sign in failed', { | ||
status: 401, | ||
}); | ||
} | ||
|
||
const token = window.crypto.randomUUID(); | ||
|
||
return NextResponse.json({ | ||
id: verifyResult.fid.toString(), | ||
token, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
import { FeedPage } from "@components/feed/FeedPage"; | ||
import { LandingPage } from "@components/landing/LandingPage"; | ||
import { getServerSession } from "next-auth"; | ||
|
||
import { authOptions } from "./api/auth/[...nextauth]/route"; | ||
import { LandingPage } from '@components/landing/LandingPage'; | ||
|
||
export default async function Home() { | ||
const session = await getServerSession(authOptions); | ||
|
||
if (session) { | ||
const { | ||
user: { fid }, | ||
} = session; | ||
return ( | ||
<div> | ||
<FeedPage fid={fid} /> | ||
</div> | ||
); | ||
} | ||
// if (session) { | ||
// const { | ||
// user: { fid }, | ||
// } = session; | ||
// return ( | ||
// <div> | ||
// <FeedPage fid={fid} /> | ||
// </div> | ||
// ); | ||
// } | ||
|
||
return <LandingPage />; | ||
} |
Oops, something went wrong.