last-login.ts 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Remember which sign-in method the user last used (local only).
  3. */
  4. export type LoginMethodId = "email" | "konnos" | "metamask" | "mavi";
  5. const KEY = "krypco_last_login_method";
  6. export function readLastLoginMethod(): LoginMethodId | null {
  7. if (typeof window === "undefined") return null;
  8. try {
  9. const v = window.localStorage.getItem(KEY);
  10. if (
  11. v === "email" ||
  12. v === "konnos" ||
  13. v === "metamask" ||
  14. v === "mavi"
  15. ) {
  16. return v;
  17. }
  18. return null;
  19. } catch {
  20. return null;
  21. }
  22. }
  23. export function writeLastLoginMethod(method: LoginMethodId): void {
  24. if (typeof window === "undefined") return;
  25. try {
  26. window.localStorage.setItem(KEY, method);
  27. } catch {
  28. /* ignore */
  29. }
  30. }
  31. export function lastLoginLabel(method: LoginMethodId): string {
  32. switch (method) {
  33. case "email":
  34. return "Email code";
  35. case "konnos":
  36. return "Konnos";
  37. case "metamask":
  38. return "MetaMask";
  39. case "mavi":
  40. return "mavi wallet";
  41. }
  42. }