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

support for receiving sharedVehicles, and adding to onsuccess #49

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
Binary file modified example-dimo-auth/dimo-network-login-with-dimo-0.0.16.tgz
Binary file not shown.
Binary file not shown.
65 changes: 37 additions & 28 deletions example-dimo-auth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example-dimo-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/node": "^16.18.114",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"@dimo-network/login-with-dimo": "file:./dimo-network-login-with-dimo-0.0.16.tgz",
"@dimo-network/login-with-dimo": "file:./dimo-network-login-with-dimo-0.0.17.tgz",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import {

<ShareVehiclesWithDimo
mode="popup"
onSuccess={(authData) => console.log("Success:", authData)}
onSuccess={(authData) => console.log("Success:", authData)} //authData will include the sharedVehicles
onError={(error) => console.error("Error:", error)}
permissionTemplateId={"1"} //REQUIRED: "1" is the template for all SACD permissions
//expirationDate={} //OPTIONAL ISO STRING
Expand Down
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.16",
"version": "0.0.17",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
10 changes: 6 additions & 4 deletions sdk/src/utils/authUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import {
} from "../storage/storageManager";

export const processAuthResponse = (
{ token, walletAddress, email }: any,
{ token, walletAddress, email, sharedVehicles }: any,
setAuthenticated: (status: boolean) => void,
onSuccess: (data: {
token: string;
transactionHash?: string;
transactionReceipt?: any;
sharedVehicles: string[]
}) => void
) => {
//This auth response may be triggered for a coupled or decoupled flow
//If decoupled, it will only return token
//If coupled, it will return token + updatedVehicles
if (walletAddress) storeWalletAddressInLocalStorage(walletAddress);
if (email) storeEmailInLocalStorage(email);
if (token) {
storeJWTInCookies(token);
setAuthenticated(true);
onSuccess({ token });
onSuccess({ token, sharedVehicles });
}
};

Expand Down
3 changes: 2 additions & 1 deletion sdk/src/utils/eventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const handleMessageForPopup = (
email,
mode,
transactionHash,
sharedVehicles,
message,
} = event.data;

Expand All @@ -93,7 +94,7 @@ export const handleMessageForPopup = (

if (eventType === "authResponse") {
processAuthResponse(
{ token, walletAddress, email },
{ token, walletAddress, email, sharedVehicles },
setAuthenticated,
onSuccess
);
Expand Down