mirror of
https://github.com/aljazceru/react-native-pubky.git
synced 2025-12-22 00:54:21 +01:00
Add base project
Implement auth method
This commit is contained in:
30
src/index.tsx
Normal file
30
src/index.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { NativeModules, Platform } from 'react-native';
|
||||
import { ok, err, type Result } from '@synonymdev/result';
|
||||
|
||||
const LINKING_ERROR =
|
||||
`The package 'react-native-pubky' doesn't seem to be linked. Make sure: \n\n` +
|
||||
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
||||
'- You rebuilt the app after installing the package\n' +
|
||||
'- You are not using Expo Go\n';
|
||||
|
||||
const Pubky = NativeModules.Pubky
|
||||
? NativeModules.Pubky
|
||||
: new Proxy(
|
||||
{},
|
||||
{
|
||||
get() {
|
||||
throw new Error(LINKING_ERROR);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
export async function auth(
|
||||
url: string,
|
||||
secretKey: string
|
||||
): Promise<Result<string[]>> {
|
||||
const res = await Pubky.auth(url, secretKey);
|
||||
if (res[0] === 'error') {
|
||||
return err(res[1]);
|
||||
}
|
||||
return ok(res[1]);
|
||||
}
|
||||
Reference in New Issue
Block a user