Ideally it should work because localStorage is supported in Safari. Either check in the settings if you have disabled JavaScript or run it on different iPad to verify if the problem is with the code.
Also, Wouldn't it be better if this is handled in the server side based on active session? storing in localStorage is vulnerable and wouldn't work in incognito mode