Three Months of a Small Site (5): One Letter, Two Return Addresses
Previous: Moving House, and a Two-Month-Old Backup | 中文版:一封信,两个回信地址
The last post in the series is about debugging WeChat sign-in. The problem was small, but the journey was fun, and it corrected a misunderstanding of my own.
How sign-in works
Open the site inside WeChat, tap “sign in”, and you pass through a few stops:
The site sends you to WeChat, and WeChat confirms who you are. WeChat then hands you to a relay service whose job is to deal with WeChat. The relay gets your identity and sends you back to the site, with a stamp that says “WeChat has vouched for this person”. The site checks the stamp and signs you in.
Think of it as posting a letter to get something done. The envelope carries a return address, and once the job is done, the reply comes back to that address.
Symptom: signed in, but back in the wrong place
After switching to a new WeChat official account, sign-in itself worked and I got my own identity. But there was one small flaw: wherever you tapped “sign in”, you ended up on the home page afterwards. You were looking at your portfolio, signed in, and had to find your way back.
The cause was almost comic: the envelope had two return addresses.
The relay’s address already included a return address of “go to the home page when done”. Before sending, the site added a second one after it: “go back to the page I came from”. Both were on the envelope, and WeChat only reads the first. The more accurate address was never used.
The fix was direct: stop adding a second address, and write “the page I came from” into the first one instead. One return address on the envelope, and the right one.
Who holds the key
Along the way I corrected a misunderstanding of my own.
At first I thought the site itself had to keep a key issued by WeChat to complete sign-in. It doesn’t. The relay is what checks identities with WeChat, and that key lives only there. All the site does is check that the relay’s stamp is genuine and fresh; a stamp more than a few minutes old is refused.
That division of labour is actually better: the most important key lives in one place, and even if something goes wrong with the site, it can’t leak that key.
Ship only what you mean to
Finally, the release. My local code held more than this fix; there were other features half-finished. Shipping the whole thing would have taken those unfinished pieces live as well.
So only this one change went out, with the old version saved first so it could be swapped back at any moment. After release I signed in through WeChat myself and checked I landed back on the page I came from. Only then was it done.
Takeaways
- When one request carries two “where to go back”, find out which one actually counts;
- Be clear about who holds each key; the most important ones should live in as few places as possible;
- Ship only what you mean to, and keep the old version;
- After the fix, walk through the real flow yourself.
Closing
In three months, a small site grew from a spreadsheet into something people use. Looking back, little of the time went into “writing features”. Much more went into things like these: is the time right, do the colours match people’s habits, does a backup exist, does sign-in bring you back to the right place.
None of it is hard; the hard part is noticing. I hope these posts are of some use to anyone working on a small project of their own.
Comments