Capacitor integration issue
# support-questions-legacy
r
Hey @war_ace when you get the fetch error, does it make an api call to the backend or error out before the api call is actually made?
w
I added a listener in express to get the request. for reference my express.js api is on my macbook at port 3000. I have my apiUrl in angular set to point at the macbook which is the 192.168.1.244. let app = express(); app.use((req, res, next) => { const now = new Date(); console.log(
${now.toISOString()} - ${req.method} ${req.url}
); console.log("Body:", req.headers); next(); // Pass control to the next middleware }); const corsOptions = { origin: [ "http://localhost:3000", "http://localhost:4200", "capacitor://localhost", "ionic://localhost", ], methods: ["GET", "POST", "OPTIONS"], allowedHeaders: [ "Content-Type", "FDI-Version", "RID", "ST-Auth-Mode", "content-type", ], credentials: true, }; app.use(cors(corsOptions)); app.use(express.json()); app.use(bodyParser.json()); app.use(middleware()); and the result I get is - OPTIONS /auth/session/refresh Body: { host: '192.168.1.244:3000', connection: 'keep-alive', accept: '*/*', 'access-control-request-method': 'POST', 'access-control-request-headers': 'fdi-version,rid,st-auth-mode', origin: 'http://localhost', 'user-agent': 'Mozilla/5.0 (Linux; Android 14; SM-S911U Build/UP1A.231005.007; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/122.0.6261.119 Mobile Safari/537.36', 'sec-fetch-mode': 'cors', referer: 'http://localhost/', 'accept-encoding': 'gzip, deflate', 'accept-language': 'en-US,en;q=0.9' } - OPTIONS /auth/signin Body: { host: '192.168.1.244:3000', connection: 'keep-alive', accept: '*/*', 'access-control-request-method': 'POST', 'access-control-request-headers': 'content-type,fdi-version,rid,st-auth-mode', origin: 'http://localhost', 'user-agent': 'Mozilla/5.0 (Linux; Android 14; SM-S911U Build/UP1A.231005.007; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/122.0.6261.119 Mobile Safari/537.36', 'sec-fetch-mode': 'cors', referer: 'http://localhost/', 'accept-encoding': 'gzip, deflate', 'accept-language': 'en-US,en;q=0.9' }
r
Can you show me the network requests made by the capacitor app?
I’m not entirely sure I understand your setup.
w
The requests are preflight OPTIONS requests made by the browser before sending the actual POST request. I don't think it ever ends up sending a post request.
r
What are the errors on the console on the frontend?
w
this is the response I get from this catch. catch (err: any) { if (err.isSuperTokensGeneralError === true) { // this may be a custom error message sent from the API by you. window.alert(err.message); } else { window.alert('Oops! Something went wrong. ' + err.message); }
r
Can you not see console errors?
w
it's a compiled app on my phone
if i just run the angular web app in the browser everything works fine. it's just when i compile it to capacitor that I have issues
r
Well, it would be hard to help without a proper error log from your side
w
I can try to do a generic post request to the api instead of the auth sdk to see if it's all post's or just the sdk having issues
r
Try it.
m
I have (maybe) a similar problem. Everything works without any problems on the web, but when I use the whole thing through Capacitor, for example in iOS, a refresh call is made all the time after logging in @rp_st
btw @war_ace you have to add
Copy code
typescript
--- 
import supertokens from 'supertokens-node';
--- 

        allowedHeaders: ['content-type', ...supertokens.getAllCORSHeaders()],
after that it works for me. I use a nestjs backend
24 Views