1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-21 14:19:39 +02:00

Enhance Plaid connection management with re-authentication and error handling (#1854)

* Enhance Plaid connection management with re-authentication and error handling

- Add support for Plaid item status tracking (good/requires_update)
- Implement re-authentication flow for Plaid connections
- Handle connection errors and provide user-friendly reconnection options
- Update Plaid link token generation to support item updates
- Add localization for new connection management states

* Remove redundant 'reconnect' localization for Plaid items
This commit is contained in:
Josh Pigford 2025-02-12 12:59:35 -06:00 committed by GitHub
parent 08a2d35308
commit f1f2e103ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 156 additions and 19 deletions

View file

@ -5,6 +5,8 @@ export default class extends Controller {
static values = {
linkToken: String,
region: { type: String, default: "us" },
isUpdate: { type: Boolean, default: false },
itemId: String
};
open() {
@ -13,15 +15,30 @@ export default class extends Controller {
onSuccess: this.handleSuccess,
onLoad: this.handleLoad,
onExit: this.handleExit,
onEvent: this.handleEvent,
onEvent: this.handleEvent
});
handler.open();
}
handleSuccess = (public_token, metadata) => {
window.location.href = "/accounts";
if (this.isUpdateValue) {
// Trigger a sync to verify the connection and update status
fetch(`/plaid_items/${this.itemIdValue}/sync`, {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"X-CSRF-Token": document.querySelector('[name="csrf-token"]').content,
}
}).then(() => {
// Refresh the page to show the updated status
window.location.href = "/accounts";
});
return;
}
// For new connections, create a new Plaid item
fetch("/plaid_items", {
method: "POST",
headers: {
@ -43,7 +60,10 @@ export default class extends Controller {
};
handleExit = (err, metadata) => {
// no-op
// If there was an error during update mode, refresh the page to show latest status
if (err && metadata.status === "requires_credentials") {
window.location.href = "/accounts";
}
};
handleEvent = (eventName, metadata) => {