Skip to content
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
35 changes: 21 additions & 14 deletions src/lib/StringPay.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
export interface StringPayload {
apiKey: string;
name: string;
collection?: string;
currency: string;
price: number;
imageSrc: string;
imageAlt?: string;
chainID: number;
userAddress: string;
contractAddress: string;
contractFunction: string;
contractReturn: string;
contractParameters: string[];
txValue: string;
options?: StringOptions;
apiKey: string;
name: string;
collection?: string;
currency: string;
price: number;
imageSrc: string;
imageAlt?: string;
chainID: number;
userAddress: string;
contractAddress: string;
contractFunction: string;
contractReturn: string;
contractParameters: string[];
txValue: string;
gasLimit?: string;
}

export interface StringOptions {
bypassDeviceCheck?: boolean;
}

export declare class StringPay {
container?: Element;
frame?: HTMLIFrameElement;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/StringPay.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createServices, type Services } from "./services";

export interface StringPayload {
options?: StringOptions
apiKey: string;
name: string;
collection?: string;
Expand All @@ -18,6 +19,10 @@ export interface StringPayload {
gasLimit?: string;
}

export interface StringOptions {
bypassDeviceCheck?: boolean;
}

const IFRAME_URL = import.meta.env.VITE_IFRAME_URL;
const API_URL = import.meta.env.VITE_API_URL;

Expand Down
6 changes: 3 additions & 3 deletions src/lib/services/apiClient.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function createApiClient({ baseUrl }: ApiClientOptions): ApiClient {
}
}

async function loginUser(nonce: string, signature: string, visitor?: VisitorData) {
async function loginUser(nonce: string, signature: string, visitor?: VisitorData, bypassDeviceCheck = false) {
const headers = { "X-Api-Key": apiKey };
const body = {
nonce,
Expand All @@ -110,7 +110,7 @@ export function createApiClient({ baseUrl }: ApiClientOptions): ApiClient {
const { data } = await httpClient.post<{
authToken: AuthToken;
user: User;
}>(`/login/sign`, body, { headers });
}>(`/login/sign${bypassDeviceCheck ? "?bypassDevice=true" : ""}`, body, { headers });
return data;
} catch (e: any) {
const error = _getErrorFromAxiosError(e);
Expand Down Expand Up @@ -243,7 +243,7 @@ export interface ApiClient {
createUser: (nonce: string, signature: string, visitor?: VisitorData) => Promise<{ authToken: AuthToken; user: User }>;
updateUser: (userId: string, userUpdate: UserUpdate) => Promise<User>;
requestEmailVerification: (userId: string, email: string) => Promise<void>;
loginUser: (nonce: string, signature: string, visitor?: VisitorData) => Promise<{ authToken: AuthToken; user: User }>;
loginUser: (nonce: string, signature: string, visitor?: VisitorData, bypassDeviceCheck?: boolean) => Promise<{ authToken: AuthToken; user: User }>;
refreshToken: (walletAddress: string) => Promise<{ authToken: AuthToken; user: User }>;
logoutUser: () => Promise<void>;
getUserStatus: (userId: string) => Promise<{ status: string }>;
Expand Down
17 changes: 12 additions & 5 deletions src/lib/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ import type { LocationService, VisitorData } from './location.service';
export function createAuthService({ apiClient, locationService }: { apiClient: ApiClient, locationService: LocationService }): AuthService {
const previousAttempt = { signature: "", nonce: "" };

let _bypassDeviceCheck = false;

const setBypassDeviceCheck = (value?: boolean) => {
_bypassDeviceCheck = value || false;
};

const login = async (nonce: string, signature: string, visitorData?: VisitorData) => {
const data = await apiClient.loginUser(nonce, signature, visitorData);
const data = await apiClient.loginUser(nonce, signature, visitorData, _bypassDeviceCheck);
return data;
};

Expand Down Expand Up @@ -42,8 +48,7 @@ export function createAuthService({ apiClient, locationService }: { apiClient: A
if (!previousAttempt.signature) throw { code: "UNAUTHORIZED" };

const visitorData = await locationService.getVisitorData();
const data = await apiClient.loginUser(previousAttempt.nonce, previousAttempt.signature, visitorData);
return data;
return login(previousAttempt.nonce, previousAttempt.signature, visitorData);
};


Expand Down Expand Up @@ -78,15 +83,17 @@ export function createAuthService({ apiClient, locationService }: { apiClient: A

return {
loginOrCreateUser,
fetchLoggedInUser,
retryLogin,
logout,
fetchLoggedInUser
setBypassDeviceCheck
};
}

export interface AuthService {
loginOrCreateUser: (walletAddress: string) => Promise<{ user: User }>;
retryLogin: () => Promise<{ user: User }>;
fetchLoggedInUser: (walletAddress: string) => Promise<User | null>;
retryLogin: () => Promise<{ user: User }>;
logout: () => Promise<any>;
setBypassDeviceCheck: (value?: boolean) => void;
}
1 change: 1 addition & 0 deletions src/lib/services/events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export function createEventsService(authService: AuthService, quoteService: Quot

apiClient.setWalletAddress(stringPay.payload.userAddress);
apiClient.setApiKey(stringPay.payload.apiKey);
authService.setBypassDeviceCheck(stringPay.payload.options?.bypassDeviceCheck);

// init fp service
locationService.getFPInstance().catch((err) => console.debug("getFPInstance error: ", err));
Expand Down