fix(mobile): update public menu URL format to https://menul.io/menu/:slug
This commit is contained in:
Binary file not shown.
@@ -1,8 +1,8 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { router } from "expo-router";
|
import { router } from "expo-router";
|
||||||
import { ActivityIndicator, View } from "react-native";
|
import { ActivityIndicator, View } from "react-native";
|
||||||
import { api } from "@/lib/api";
|
import { api, ApiError } from "@/lib/api";
|
||||||
import { getActiveRestaurant, setActiveRestaurant } from "@/lib/active-restaurant";
|
import { clearActiveRestaurant, getActiveRestaurant, setActiveRestaurant } from "@/lib/active-restaurant";
|
||||||
import { supabase } from "@/lib/supabase";
|
import { supabase } from "@/lib/supabase";
|
||||||
|
|
||||||
interface MeRestaurantResponse {
|
interface MeRestaurantResponse {
|
||||||
@@ -55,6 +55,19 @@ export default function Index() {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Index resolve error:", e);
|
console.warn("Index resolve error:", e);
|
||||||
|
|
||||||
|
// A 401 here means the cached session's token is no longer valid
|
||||||
|
// server-side (expired refresh token, deleted user, etc.) — that is
|
||||||
|
// not the same as "no restaurant yet", so send them to login instead
|
||||||
|
// of silently starting onboarding with a broken session.
|
||||||
|
if (e instanceof ApiError && e.status === 401) {
|
||||||
|
await clearActiveRestaurant();
|
||||||
|
await supabase.auth.signOut();
|
||||||
|
if (!cancelled) {
|
||||||
|
router.replace("/(auth)/login");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cancelled) {
|
if (!cancelled) {
|
||||||
|
|||||||
@@ -2,6 +2,15 @@ import { supabase } from "./supabase";
|
|||||||
|
|
||||||
const API_URL = process.env.EXPO_PUBLIC_API_URL ?? "http://localhost:3001";
|
const API_URL = process.env.EXPO_PUBLIC_API_URL ?? "http://localhost:3001";
|
||||||
|
|
||||||
|
export class ApiError extends Error {
|
||||||
|
status: number;
|
||||||
|
|
||||||
|
constructor(status: number, message: string) {
|
||||||
|
super(message);
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function authHeaders(): Promise<Record<string, string>> {
|
async function authHeaders(): Promise<Record<string, string>> {
|
||||||
const { data } = await supabase.auth.getSession();
|
const { data } = await supabase.auth.getSession();
|
||||||
const token = data.session?.access_token;
|
const token = data.session?.access_token;
|
||||||
@@ -17,7 +26,7 @@ async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
|
|||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const body = await res.json().catch(() => ({ message: res.statusText }));
|
const body = await res.json().catch(() => ({ message: res.statusText }));
|
||||||
throw new Error(body.message ?? `Request failed: ${res.status}`);
|
throw new ApiError(res.status, body.message ?? `Request failed: ${res.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.status === 204) return undefined as T;
|
if (res.status === 204) return undefined as T;
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
const WEB_BASE_URL = process.env.EXPO_PUBLIC_WEB_URL || "http://localhost:3000";
|
const WEB_BASE_URL = (process.env.EXPO_PUBLIC_WEB_URL || "https://menul.io").replace(/\/+$/, "");
|
||||||
|
|
||||||
export function getPublicMenuUrl(slug: string): string {
|
export function getPublicMenuUrl(slug: string): string {
|
||||||
if (WEB_BASE_URL.includes("menul.io")) {
|
|
||||||
return `https://${slug}.menul.io`;
|
|
||||||
}
|
|
||||||
return `${WEB_BASE_URL}/menu/${slug}`;
|
return `${WEB_BASE_URL}/menu/${slug}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPublicMenuDisplayUrl(slug: string): string {
|
export function getPublicMenuDisplayUrl(slug: string): string {
|
||||||
if (WEB_BASE_URL.includes("menul.io")) {
|
const displayBase = WEB_BASE_URL.replace(/^https?:\/\//, "");
|
||||||
return `${slug}.menul.io`;
|
return `${displayBase}/menu/${slug}`;
|
||||||
}
|
|
||||||
return `${WEB_BASE_URL.replace(/^https?:\/\//, "")}/menu/${slug}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user