Repository navigation
fix(api): decide /api or /webrest at login only - #272
Conversation
Any 404 from an /api endpoint, or a network error on login, switched the client to /webrest and saved it in the account, so the next sessions kept using /webrest. NethVoice 1.9 will stop publishing /webrest and /socket.io, and such accounts would stay broken. Probe /api/login first on every login and use /webrest only when it answers 404, that is a PBX without the middleware. Other errors are returned to the caller and never change the path. A restored session follows its token: JWT uses /api, only a legacy hash token uses /webrest, so a stored apiBasePath of /webrest is ignored. Phone Island saves the API mode it probes in localStorage and never probes again: set it from the login result, so a stale legacy mode does not keep it on /webrest and /socket.io. Refs NethServer/dev#8358
fdefaa8 to
561da68
Compare
tonyco97
left a comment
There was a problem hiding this comment.
CI green on all 4 targets. Traced auto-login: non-JWT accounts go through Authentication.login, which now probes /api/login first, so legacy accounts move to /api after a PBX upgrade 👍. Main point is how this interacts with nethesis/phone-island#322; the rest are questions and nits.
Two nits on lines outside the diff:
- 🔵 nit:
AccountController.ts:131: the comment "follows account settings/fallback logic" is out of date: there is no fallback anymore and the storedapiBasePathis ignored. - 🔵 nit:
apiBasePathis still written in 3 places inuseNethVoiceAPI.tsbut never read. Keep it only if it's meant for downgrade compatibility; otherwise drop it fromAccount.
Treat a 405 on /api/login like a 404, as a PBX without the middleware may answer either, and report a network error as a lost connection instead of wrong credentials. Drop apiBasePath from the account: nothing reads it anymore. Update the comments on the Phone Island API mode and on the token check.
|
Also fixed the two notes outside the diff in 138b505: the comment at |
tonyco97
left a comment
There was a problem hiding this comment.
Thanks, 405 handling, the comment updates and the apiBasePath removal look good, CI green. One regression from the new network-error branch below.
The plain errors thrown during login, such as a user without a NethLink extension, have no response either and were reported as a lost connection. Check them first and match only failed axios requests.
tonyco97
left a comment
There was a problem hiding this comment.
All review points addressed in 1254081, thanks. Re-checked the login error mapping: plain errors thrown inside the try (User not authorized for NethLink, No token received) no longer end up as "Network connection lost", only failed axios requests and 404 do. CI green on all 4 targets.
Phone Island 1.1.9 probes the API mode on every start instead of keeping the mode saved by older versions.
Phone Island 1.1.9 probes the API mode on every start, so NethLink no longer needs to overwrite the mode saved by older versions.
NethVoice 1.9 will stop publishing the legacy CTI server on
/webrestand/socket.io(nethesis/ns8-nethvoice#1308): every client must use the middleware on/apiand/api/ws. This fix must ship before that, so users are not locked out.NethLink could get stuck on
/webrest: any 404 from an/apiendpoint (or a network error on login) switched the client to/webrestand saved it in the account, so later sessions kept using it. On NethVoice 1.9 those accounts would stay broken./api/loginis always tried first,/webrestis used only when/api/loginitself answers 404 or 405 (a PBX without the middleware). Other errors are returned to the caller and never change the path; a network error is reported as a lost connection instead of wrong credentials./api, only a legacy hash token uses/webrest. TheapiBasePathsaved by older releases is ignored and no longer written, so stuck accounts recover on the next start.@nethesis/phone-islandto v1.1.9 (fix(api): probe the API mode on every init nethesis/phone-island#322): older versions saved the API mode they probed in localStorage and never probed again, so a stalelegacymode kept them on/webrestand/socket.io. The new version probes on every start.Tested with
npm run typecheckand a harness arounduseNethVoiceAPIwith a mocked HTTP client: new PBX, stored/webrestwith a JWT, 404 on a non-login endpoint (no switch), network error and 503 on/api/login(no switch), legacy PBX (/api/login404, hash login on/webrest), legacy account restored, PBX upgraded after a legacy login.NethServer/dev#8358