Skip to content

Commit

Permalink
Merge pull request #31 from DIMO-Network/development
Browse files Browse the repository at this point in the history
v0.0.10 Dev -> Main
  • Loading branch information
MoizAhmedd authored Dec 2, 2024
2 parents 581b20d + b90539b commit c30bb03
Show file tree
Hide file tree
Showing 18 changed files with 333 additions and 329 deletions.
Binary file not shown.
Binary file modified example-dimo-auth/dimo-network-login-with-dimo-0.0.9.tgz
Binary file not shown.
70 changes: 39 additions & 31 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.9.tgz",
"@dimo-network/login-with-dimo": "file:./dimo-network-login-with-dimo-0.0.10.tgz",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
Expand Down
11 changes: 10 additions & 1 deletion example-dimo-auth/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {

function App() {
const [permissionsEnabled, setPermissionsEnabled] = useState(false);
const { isAuthenticated, getValidJWT } = useDimoAuthState();
const { isAuthenticated, getValidJWT, email, getEmail, walletAddress } =
useDimoAuthState();

const sampleAbi = [
{
Expand Down Expand Up @@ -1120,6 +1121,14 @@ function App() {
</label>
</div>

{isAuthenticated && (
<div>
<p>Connected User</p>
<p>Wallet Address:{walletAddress}</p>
{email && <p>{email}</p>}
</div>
)}

<div>
<h3>Popup Example</h3>

Expand Down
42 changes: 21 additions & 21 deletions sdk/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 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.9",
"version": "0.0.10",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
19 changes: 17 additions & 2 deletions sdk/src/auth/context/DimoAuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// DimoAuthContext.tsx
import React, { createContext, useContext, useEffect, useState } from "react";
import { getJWTFromCookies } from "../../storage/storageManager";
import { getEmailFromLocalStorage, getJWTFromCookies, getWalletAddressFromLocalStorage } from "../../storage/storageManager";
import { isTokenExpired } from "../../token/tokenManager";

// Define the type of the context
type DimoAuthContextType = {
isAuthenticated: boolean; // Read-only for app developers
walletAddress: string | null;
email: string | null;
getValidJWT: () => string | null;
getEmail: () => string | null;
};

// Create the context
Expand All @@ -29,6 +32,18 @@ export const DimoAuthProvider = ({
children: React.ReactNode;
}) => {
const [isAuthenticated, setAuthenticated] = useState(false);

const hasEmailPermission = !!getEmailFromLocalStorage();
const email = hasEmailPermission ? getEmailFromLocalStorage() : "";
const walletAddress = getWalletAddressFromLocalStorage();

const getEmail = () => {
if (hasEmailPermission) {
return email;
} else {
throw new Error("No permission to access email");
}
};


const getValidJWT = () => {
Expand All @@ -47,7 +62,7 @@ export const DimoAuthProvider = ({
}, []);

return (
<DimoAuthContext.Provider value={{ isAuthenticated, getValidJWT }}>
<DimoAuthContext.Provider value={{ isAuthenticated, getValidJWT, email, getEmail, walletAddress }}>
<DimoAuthUpdaterContext.Provider value={{ setAuthenticated }}>
{children}
</DimoAuthUpdaterContext.Provider>
Expand Down
34 changes: 4 additions & 30 deletions sdk/src/auth/embedAuth.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
import { EntryState } from "../enums/globalEnums";
import { BasePayload } from "../types/BasePayload";
import { TransactionData } from "../types/TransactionData";
import { handleMessageForEmbed } from "../utils/eventHandler";

export const embedAuth = (
entryState: EntryState,
onSuccess: (data: {
token: string;
transactionHash?: string;
transactionReceipt?: any;
}) => void,
onError: (error: Error) => void,
setAuthenticated: React.Dispatch<React.SetStateAction<boolean>>,
dimoLogin: string,
clientId?: string,
redirectUri?: string,
apiKey?: string,
permissionTemplateId?: string,
vehicles?: string[],
vehicleMakes?: string[],
transactionData?: TransactionData
basePayload: BasePayload,
data?: Record<string, any>
) => {
const cleanup = handleMessageForEmbed(
dimoLogin,
entryState,
onSuccess,
onError,
setAuthenticated,
clientId,
redirectUri,
apiKey,
permissionTemplateId,
vehicles,
vehicleMakes,
transactionData
);
const cleanup = handleMessageForEmbed(basePayload, data);
};
Loading

0 comments on commit c30bb03

Please sign in to comment.