Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes undefined config variables in standalone builds leading to crashes #7

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/KindeAuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ global.atob = decode;

export const KindeAuthProvider = ({
children,
config,
}: {
children: React.ReactNode;
config: {
domain: string | undefined;
clientId: string | undefined;
scopes?: string;
};
}) => {
const domain = process.env.EXPO_PUBLIC_KINDE_DOMAIN!;
const clientId = process.env.EXPO_PUBLIC_KINDE_CLIENT_ID!;
const scopes =
process.env.EXPO_PUBLIC_KINDE_SCOPES?.split(" ") ||
DEFAULT_TOKEN_SCOPES.split(" ");
const domain = config.domain;
if (domain === undefined)
throw new Error("KindeAuthProvider config.domain prop is undefined");

const clientId = config.clientId;
if (clientId === undefined)
throw new Error("KindeAuthProvider config.clientId prop is undefined");

const scopes = config.scopes?.split(" ") || DEFAULT_TOKEN_SCOPES.split(" ");

const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);
const redirectUri = makeRedirectUri({ native: Constants.isDevice });
Expand Down
14 changes: 6 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ pnpm add @kinde/expo

## **Environment variables**

```bash
EXPO_PUBLIC_KINDE_DOMAIN=[yourapp.kinde.com]
EXPO_PUBLIC_KINDE_CLIENT_ID="ApplicationClientId"
// Optional (default: "openid profile email offline")
EXPO_PUBLIC_KINDE_SCOPES="openid profile email offline"
```

The redirection URL is automatically computed using Expo Auth Session `makeRedirectUri` function. You can find more information about this function [here](https://docs.expo.dev/versions/latest/sdk/auth-session/#makeRedirectUri).

## Integrate with your app
Expand All @@ -30,7 +23,12 @@ import { KindeAuthProvider } from '@kinde/expo';

export default function App() {
return (
<KindeAuthProvider>
<KindeAuthProvider config={{
domain: "your-app.kinde.com", // Required
clientId: "your-client-id", // Required
// Optional (default: "openid profile email offline")
scopes: "openid profile email offline",
}}>
<!-- Your application code -->
</KindeAuthProvider>
);
Expand Down