DEV Community

Cover image for How I Smashed a Bug in a Shared Authentication Library

How I Smashed a Bug in a Shared Authentication Library

Daniel Balcarek on August 05, 2026

This is a submission for DEV's Summer Bug Smash: Smash Stories powered by Sentry. This happened a while ago at one of the corporations where I wor...
Collapse
 
technogamerz profile image
𝐓𝐡𝐞 𝐋𝐚𝐳𝐲 𝐆𝐢𝐫𝐥

The cover image looks good! haha

Collapse
 
klaudiagrz profile image
Klaudia Grzondziel

Agree! 💯 Looks awesome! 😄

Collapse
 
jim-wilson profile image
Jim Wilson

Yep !!

Collapse
 
gramli profile image
Daniel Balcarek

Thanks to both of you @technogamerz, @klaudiagrz ! I played around with it a lot. Did you notice the LOTR theme? 😄 Especially the hobbit and Smaug. 😄

Collapse
 
klaudiagrz profile image
Klaudia Grzondziel

Ahahah, that was my guess! 😄 It gives LOTR or WoW vibes!

Thread Thread
 
gramli profile image
Daniel Balcarek

You have an excellent eye! 😮 I’m pretty sure my first prompt included both LOTR and WoW (World of Warcraft). I’m a big fan of both btw. 😅

Collapse
 
klaudiagrz profile image
Klaudia Grzondziel • Edited

Hi Daniel, great article (and awesome cover image 😄)! One thing that stopped me:

reimplemented the entire client-side authentication flow directly against the existing corporate authentication service

I know I'm probably living in a dream world, but actually this is what should happen every time when testing a new feature. How did it look in your case? You did not have QAs test the feature? Or did nobody consider such a case? Now that I think about it, I probably wouldn't think of opening so many tabs 🤔 Interesting.

Collapse
 
gramli profile image
Daniel Balcarek

Thanks! I hope I understood your question correctly. 😅

The feature was tested by our QAs, but this particular case was not discovered before the release. It required multiple tabs to refresh their tokens at just the right or wrong time, so it was an intermittent race condition rather than a consistently reproducible scenario.

One tab refreshed the token and invalidated the previous refresh token, while another tab was still trying to use it. The bigger problem was that the shared frontend library could not recover from the resulting 403 Forbidden response and left that tab completely stuck.

So yes, opening the application in multiple tabs was considered a normal use case, but nobody anticipated this exact token-refresh race condition during the original testing. Even after we identified it, the team maintaining the shared library was unable to reproduce it.. 😄

When I reimplemented the authentication flow(as part of the bug fix 😁), it went through QA again. They tested the original scenario directly, but the fix was also exercised indirectly during other test cases where opening multiple tabs was part of the testing process.

Collapse
 
klaudiagrz profile image
Klaudia Grzondziel

Ah, I see now. Thank you for the explanation. So tricky! 🐛

Collapse
 
sylwia-lask profile image
Sylwia Laskowska

Hahaha, that's a beautiful story! 🤣 Corporate "helpful" shared services at their finest.

We have something very similar in my company, too. The only difference is that ours isn't a collection of separate building blocks, but it's one huge framework. 😅

The people maintaining it seem to believe nobody will ever have to upgrade it, because every new version comes with breaking changes as if there were no tomorrow. They'll rename classes, methods... sometimes something goes from close() to closeDialog(), only to become close() again two versions later. Truly groundbreaking changes. 😂

At this point, the more we work around it and build our own implementations where it makes sense, the healthier our project tends to be. 😄

Collapse
 
gramli profile image
Daniel Balcarek

Thanks!

That’s hilarious. 😂 It looks like the lifecycle of these “helpful” shared services is the same in every corporation.😂

Sometimes I feel like the maintainers develop these libraries mainly for their own test applications. At first, every team tries to use them to save time, but after enough struggles, many teams just reimplement the features themselves. Constant breaking changes combined with little willingness to fix bugs is just... corporate life. 😂

Collapse
 
sylwia-lask profile image
Sylwia Laskowska

Hahaha, and by the way, I see you've shown up with yet another great story... clearly you're after the skateboard I wanted to win! 🤣

Thread Thread
 
gramli profile image
Daniel Balcarek

Nah, I just wanted to share a funny story from my own experience. 😄 I don’t think this is a winning one, there are plenty of much better submissions, including yours!

So let someone else break their leg on that skateboard. 🤣

Collapse
 
webdeveloperhyper profile image
Web Developer Hyper

Wow! You solved a problem that neither the frontend team nor the backend team could solve. I wouldn't expect anything less from you! This post will definitely earn you even more fans around the world! 😍

Collapse
 
gramli profile image
Daniel Balcarek

Thanks, I’m glad you liked it!❤️

You’re overestimating me. 😅 I think they were perfectly capable of fixing it, they just weren’t willing to spend the time on what they considered an edge case.

Collapse
 
capestart profile image
CapeStart

The fastest way to find out how many applications depend on your auth library is to introduce a bug in it. 😅

Collapse
 
gramli profile image
Daniel Balcarek

Truer words have never been spoken. 🤣🤣

Collapse
 
henry_robt_ed01d31ae3d216 profile image
Henry Robt

Great bug-smash story. The multi-tab token refresh race is a good example of how an intermittent issue can slip past normal testing, especially when multiple teams own different parts of the authentication flow. I also like the lesson about owning critical code when a shared dependency becomes a blocker—sometimes simplifying the architecture is the best fix.

Collapse
 
gramli profile image
Daniel Balcarek

Thanks! Glad you liked it. I agree, sometimes simplifying things ends up being the best fix.

Collapse
 
hiper2d profile image
Aliaksei Zelianouski

I hate the ownership model so popular in large companies and enterprises - lots of specialized teams with their own managers and scopes. When something breaks in between, nobody is interested in fixing it. Not because they are lazy or something - it's just extra scope nobody planned. Cross-team coordination is painful, there is no single manager or lead who can clearly prioritize this.

Yeah, you found the best solution in this situation. Got rid of dependencies on teams you have no control over.

Collapse
 
gramli profile image
Daniel Balcarek

Yes, that’s another side of the problem. When a team has multiple products to maintain, shared libraries often receive a lower priority, and managers may not want to allocate development capacity to them. Thanks for bringing up this perspective.

In this particular case, though, it wasn’t that they completely ignored the issue they did spend time investigating it. I think the bigger problem was that they didn’t want to prioritize a tricky bug that they considered an edge case.

Collapse
 
dropzilla_site_bee900de05 profile image
dp

Great bug smash story! The multi-tab refresh token race condition is exactly the kind of issue that can waste days when ownership is split across different teams. I especially liked the decision to remove the shared library and take control of the authentication flow instead of waiting indefinitely for a fix.
Stories like this are really valuable for developers because they show that debugging is not only about finding the technical cause, but also about dealing with architecture and team boundaries. We share similar practical development experiences and tutorials on codecan.net, especially around web development and real-world coding problems, so this was a very relatable read.

Thanks for sharing the full investigation and the final solution!

Collapse
 
jim-wilson profile image
Jim Wilson

One question I’d be curious about: if you had to solve this today without removing the shared library, would you try to fix the refresh-token race condition at the library level or handle token coordination in the application?

Collapse
 
gramli profile image
Daniel Balcarek

I would definitely push the frontend team to fix it at the library level, or I’d create a PR to their repo myself. Fixing it only on our application level would never be a real fix, it would just be bending around the actual problem.

Collapse
 
jacobfoster21 profile image
jacob foster

Multi-tab authentication issues can be incredibly hard to trace, especially with shared services. A solid reminder to investigate beyond your own code.

Collapse
 
gramli profile image
Daniel Balcarek

Yep, I think the debugging is one of the reasons why I still remember this bug even after all these years.

Collapse
 
tech_grundy profile image
The Tech Grundy

"Users should not open the application in multiple tabs" is such a classic corporate hand-off response!

You highlighted one of the biggest hidden costs of shared internal libraries: when no single team truly takes responsibility for edge cases, owning your own code—even if it means a two-day rewrite—is often faster and far less stressful than playing diplomat between two uncooperative teams. Fixing the multi-tab race condition directly inside your HTTP interceptor to gracefully catch that 403 was a super satisfying resolution. Great Bug Smash submission!

Multi-tab authentication race conditions are easily some of the trickiest bugs to track down, especially when token invalidation is enforced immediately on the backend!

The journey of gathering logs, getting both teams into a ticket, and still hitting the "works on my machine / don't open multiple tabs" wall is so relatable. Reimplementing the refresh flow directly into your Angular HTTP interceptor so failed refresh attempts don't freeze the tab session was 100% the right call. Great read!

Collapse
 
gramli profile image
Daniel Balcarek

Thanks, I’m glad you enjoyed reading it!

And yes, you’re right, but as a proper developer, I first had to try to get the original shared library fixed. That attempt failed, and I’m pretty sure the bug is still there to this day..but that’s corporate life. 😂

Collapse
 
codemonkei profile image
Codemonkei

This brought back some memories. 😄

The biggest takeaway for me is that ownership boundaries can become a bigger problem than the actual bug. When multiple teams own different pieces of the stack, it's surprisingly easy for everyone to conclude, "not our problem."

I also think your decision to replace the shared library was justified. Sometimes reducing dependencies and owning a critical part of your application is less risky than waiting weeks for a fix that may never come.

Great story—I'm sure many developers who've worked in large organizations have experienced something similar.

Collapse
 
gramli profile image
Daniel Balcarek

Yes, that was one of the main points of the story, ownership boundaries in large companies can sometimes become a bigger problem than the bug itself.

Thanks, I’m glad you liked it!

Collapse
 
leviyi profile image
leviyi

The multi-tab refresh token race condition is such a classic pain — we hit something almost identical and ended up serializing token refreshes with a simple lock so only one tab renews at a time. Honestly the real happy ending here is owning the code; "cannot reproduce, just don't use multiple tabs" is peak shared-library energy.

Collapse
 
gramli profile image
Daniel Balcarek

Nice! I thought a lot of developers could relate to this story, even if they ran into a similar situation with a completely different kind of bug.

In my case, I ended up keeping separate token state for each tab, so each tab could refresh its token independently when needed.

And yep, “just don’t use multiple tabs” is definitely also peak corporate energy sometimes. 😂

Thanks for reading!

Collapse
 
xulingfeng profile image
xulingfeng

Good Luck!

Collapse
 
gramli profile image
Daniel Balcarek

You mean good luck surviving the ridiculousness of corporate life? 😄

Collapse
 
xulingfeng profile image
xulingfeng

Haha, speaking as a QA, you're exactly my kind of developer.And good luck with DEV's Summer Bug Smash: Smash Stories — hope you bring it home! 🏆

Thread Thread
 
gramli profile image
Daniel Balcarek

Oh, thanks! ❤️ But I suppose there will be much better submissions. I did not really think of this as a winning one. It was just one of the “funny” stories I have from fixing bugs in the corporate world. 😄

Thread Thread
 
xulingfeng profile image
xulingfeng

The world is tattered and torn, but there's always someone quietly stitching it back together.
Here's to everyone who gives more than they take.👊

Thread Thread
 
gramli profile image
Daniel Balcarek

Beautifully said! 👊

Collapse
 
harsh2644 profile image
Harsh

Great Article Daniel Users should not open the application in multiple tabs said no product manager ever. 😄

This is the most relatable corporate debugging story I've read in a while. The not our problem ping-pong, the ticket that goes nowhere, and finally just rewriting the whole thing yourself chef's kiss. 👨‍🍳

The best part? You spent 2 days rewriting it, which is probably less time than you spent waiting for those two teams to respond. 😂

Great submission!

Collapse
 
gramli profile image
Daniel Balcarek

Thanks, Harsh! I appreciate it.

And yes, honestly, if I remember correctly, the whole process with debugging, gathering logs, and the ticket ping-pong between teams, probably took more than two months. The actual rewrite took only two days, but the time I had already spent trying to get the shared library fixed... 😂

Collapse
 
innovationsiyu profile image
Siyu

The debugging was the easy part. The real cost was walking logs between teams that each believed the problem lived somewhere else. Coordination failure is a discovery problem in disguise, because nobody knew who actually owned the edge between the two systems. That is the situation I keep thinking about when building human discovery in Opportunity Skill. You describe the person you need in plain language, say the owner of a shared library who has fixed token race conditions, and semantic matching searches recorded profiles and impressions instead of org charts. Cross-boundary bugs mostly die of routing, not diagnosis.

Collapse
 
gramli profile image
Daniel Balcarek

The debugging itself wasn’t exactly easy either. It was a race condition that was difficult to reproduce, which is probably why I still remember it after all these years. 😄

But yes, the longest part of resolving this bug was getting the issue to the right team and establishing who actually owned it. Convincing the frontend library team that the problem was on their side was another challenge. I also think there was limited motivation to prioritize the fix because, from their perspective, it was an edge case and a particularly tricky one to reproduce.

Collapse
 
ella_learns profile image
Ella Agu

Sounds really cool 😅 well done

Collapse
 
thelextimes profile image
Lex Alexander

I worked with Angular years ago and came across a similar issue. Also, I've done something similar with Axios in terms of using interceptors.

Collapse
 
publiflow profile image
PubliFlow

Interesting Angular approach. One thing I'd add is the value of the strict template checking — catching binding errors at compile time rather than runtime saves a lot of debugging hours.

Collapse
 
fuweismartocr profile image
fuweismartocr

Great topic! Shared auth libraries are such a critical single point of failure. I’m curious — was this bug related to edge cases in token validation or race conditions?

Collapse
 
gramli profile image
Daniel Balcarek

Thanks! It was a race condition in the token refresh flow. One tab refreshed the token and invalidated the previous refresh token while another tab was still trying to use it. The shared authentication library then failed to recover from the resulting 403 Forbidden response.

Collapse
 
publiflow profile image
PubliFlow

Solid Angular coverage. For Angular devs who also deal with content and images, we have a free AI toolkit at tools.shopveigo.com — background remover, upscaler, even a resume optimizer. Might save some time.

Collapse
 
innovationsiyu profile image
Siyu

The race condition itself is textbook token rotation without a grace window, but the real bug was the organisational ping pong. Weeks lost to tickets because ownership sat between two teams. In my experience the fastest fix is finding the one person who genuinely understands the problem, not the team that nominally maintains it. That hunt for the right human is exactly what human discovery in Opportunity Skill tries to shorten, since semantic search matches people on what they actually do rather than on job titles. Ownership beats committees every time.