1- import { initializeWithConfig , WithJWTParams } from '@iterable/web-sdk' ;
2- import axios from 'axios' ;
1+ import {
2+ InitializeParams ,
3+ initializeWithConfig ,
4+ WithJWT
5+ } from '@iterable/web-sdk' ;
6+ import axios , { AxiosResponse } from 'axios' ;
37import './styles/index.css' ;
48
5- import { BrowserRouter , Routes , Route } from 'react-router-dom' ;
6- import styled from 'styled-components' ;
79import { createRoot } from 'react-dom/client' ;
8- import { Home } from './views/Home' ;
9- import { Commerce } from './views/Commerce' ;
10- import { Events } from './views/Events' ;
11- import { Users } from './views/Users' ;
12- import { InApp } from './views/InApp' ;
13- import { EmbeddedMessage } from './views/Embedded' ;
10+ import { BrowserRouter , Route , Routes } from 'react-router-dom' ;
11+ import styled from 'styled-components' ;
1412import { Link } from './components/Link' ;
1513import { LoginForm } from './components/LoginForm' ;
16- import { EmbeddedMsgs } from './views/EmbeddedMsgs' ;
17-
1814import { UserProvider } from './context/Users' ;
19- import { EmbeddedMsgsImpressionTracker } from './views/EmbeddedMsgsImpressionTracker' ;
15+ import {
16+ Home ,
17+ Commerce ,
18+ Events ,
19+ Users ,
20+ InApp ,
21+ EmbeddedMsgs ,
22+ EmbeddedMessage ,
23+ EmbeddedMsgsImpressionTracker
24+ } from './views' ;
2025
2126const Wrapper = styled . div `
2227 display: flex;
@@ -41,32 +46,44 @@ const HomeLink = styled(Link)`
4146` ;
4247
4348( ( ) : void => {
44- const initializeParams : WithJWTParams = {
45- authToken : process . env . API_KEY || '' ,
49+ const authToken = process . env . API_KEY || '' ;
50+ const jwtGenerator =
51+ process . env . JWT_GENERATOR || 'http://localhost:5000/generate' ;
52+ const jwtSecret = process . env . JWT_SECRET || '' ;
53+ const useJwt = process . env . USE_JWT === 'true' ;
54+
55+ const initializeParams : InitializeParams = {
56+ authToken,
4657 configOptions : {
4758 isEuIterableService : false ,
4859 dangerouslyAllowJsPopups : true
4960 } ,
50- generateJWT : ( { email, userID } ) =>
51- axios
52- . post (
53- process . env . JWT_GENERATOR || 'http://localhost:5000/generate' ,
54- {
55- exp_minutes : 2 ,
56- email,
57- user_id : userID ,
58- jwt_secret : process . env . JWT_SECRET
59- } ,
60- {
61- headers : {
62- 'Content-Type' : 'application/json'
63- }
64- }
65- )
66- . then ( ( response : any ) => response . data ?. token )
61+ ...( useJwt
62+ ? {
63+ generateJWT : ( { email, userID } : { email : string ; userID : string } ) =>
64+ axios
65+ . post (
66+ jwtGenerator ,
67+ {
68+ exp_minutes : 2 ,
69+ email,
70+ user_id : userID ,
71+ jwt_secret : jwtSecret
72+ } ,
73+ { headers : { 'Content-Type' : 'application/json' } }
74+ )
75+ . then (
76+ ( response : AxiosResponse < { token : string } > ) =>
77+ response . data ?. token
78+ )
79+ }
80+ : { } )
6781 } ;
68- const { setEmail, setUserID, logout, refreshJwtToken } =
82+ const { setEmail, setUserID, logout, ... rest } =
6983 initializeWithConfig ( initializeParams ) ;
84+ const refreshJwtToken = useJwt
85+ ? ( rest as Partial < WithJWT > ) . refreshJwtToken
86+ : undefined ;
7087
7188 const container = document . getElementById ( 'root' ) ;
7289 const root = createRoot ( container ) ;
0 commit comments