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

Version Bump + Docs #16

Merged
merged 2 commits into from
Nov 19, 2024
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
57 changes: 36 additions & 21 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,44 @@ yarn add @dimo-network/login-with-dimo
## Usage
You can integrate the LoginWithDimo component into your React application to allow users to authenticate with Dimo. The component handles the authentication process in a popup window and triggers the appropriate callback functions upon success or error.

### Example
### Initialize DIMO SDK

```
import { LoginWithDimo } from "@dimo-network/login-with-dimo";

const YourComponent = () => {
const permissionsEnabled = true; // Set permissions flag based on your app's requirements

return (
<LoginWithDimo
mode="redirect" //can be set to "redirect", "popup", or "embed"
onSuccess={(authData) => console.log("Success:", authData)} // Success callback, will only trigger on "embed" or "popup" modes, authData is an object, with a "token" param which represents the users JWT
onError={(error) => console.error("Error:", error)} // Error callback
clientId={process.env.REACT_APP_DIMO_CLIENT_ID} // Your Dimo Client ID
redirectUri={process.env.REACT_APP_DIMO_REDIRECT_URI} // Your redirect URI after login, this is relevant for the "redirect" mode
apiKey={process.env.REACT_APP_DIMO_API_KEY} // Your Dimo API Key (optional)
permissionTemplateId={permissionsEnabled ? "1" : undefined} // Permission template ID (optional, default to 1 if need to request permissions)
environment={process.env.REACT_APP_DIMO_ENV} // Environment setting (e.g., "production" or "development"), de
// Optionally, specify vehicles (uncomment the line below to use it)
// vehicles={["585","586"]} // Specify the vehicles to be accessed after login
/>
);
};
import {
initializeDimoSDK,
} from "@dimo-network/login-with-dimo";

initializeDimoSDK({
clientId: "YOUR CLIENT ID",
redirectUri: "YOUR REDIRECT URI",
apiKey: "YOUR API KEY",
environment: "development" | "production",
});
```

### Using the Button Components

```
import {
LoginWithDimo,
ShareVehiclesWithDimo,
} from "@dimo-network/login-with-dimo";

<LoginWithDimo
mode="popup"
onSuccess={(authData) => console.log("Success:", authData)}
onError={(error) => console.error("Error:", error)}
permissionTemplateId={permissionsEnabled ? "1" : undefined} //This will control if your users are asked to share vehicles, as part of the login flow. "1" is the template for all SACD permissions
// Optionally, specify vehicles (uncomment the line below to use it)
// vehicles={["585","586"]} // Specify the vehicles to be accessed after login
/>

<ShareVehiclesWithDimo
mode="popup"
onSuccess={(authData) => console.log("Success:", authData)}
onError={(error) => console.error("Error:", error)}
permissionTemplateId={"1"} //REQUIRED: "1" is the template for all SACD permissions
// Optionally, specify vehicles (uncomment the line below to use it)
// vehicles={["585","586"]} // Specify the vehicles to be accessed when triggered
/>
```
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dimo-network/login-with-dimo",
"version": "0.0.3",
"version": "0.0.4",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down