64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
const HONO = "http://192.168.1.225:3456";
|
|
|
|
async function main() {
|
|
// 1. Signup
|
|
console.log("=== Signup ===");
|
|
const signup = await fetch(`${HONO}/api/admin/signup`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ email: "test@fam.com", password: "password123", famName: "Test Fam" }),
|
|
});
|
|
const signupData = await signup.json();
|
|
console.log("Signup:", JSON.stringify(signupData, null, 2));
|
|
|
|
// 2. Login
|
|
console.log("\n=== Login ===");
|
|
const login = await fetch(`${HONO}/api/admin/login`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ email: "test@fam.com", password: "password123" }),
|
|
});
|
|
const loginData = await login.json();
|
|
console.log("Login:", JSON.stringify(loginData, null, 2));
|
|
|
|
// 3. Get invite code from fams directly via PB
|
|
const pbTokenRes = await fetch("http://192.168.1.225:8090/api/collections/_superusers/auth-with-password", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ identity: "debug@famchamp.dev", password: "debug123" }),
|
|
});
|
|
const pbTokenData = await pbTokenRes.json();
|
|
const pbSuperToken = pbTokenData.token;
|
|
|
|
const famsRes = await fetch("http://192.168.1.225:8090/api/collections/fams/records?sort=-created", {
|
|
headers: { Authorization: `Bearer ${pbSuperToken}` },
|
|
});
|
|
const famsData = await famsRes.json();
|
|
const fam = famsData.items[0];
|
|
console.log("\n=== Fam ===");
|
|
console.log("Fam:", JSON.stringify(fam, null, 2));
|
|
console.log("Invite code:", fam.inviteCode);
|
|
|
|
// 4. Join as member
|
|
console.log("\n=== Join ===");
|
|
const join = await fetch(`${HONO}/api/members/join`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ inviteCode: fam.inviteCode, name: "Kid", deviceToken: "dev-token-xyz" }),
|
|
});
|
|
const joinData = await join.json();
|
|
console.log("Join:", JSON.stringify(joinData, null, 2));
|
|
|
|
// 5. Verify member
|
|
console.log("\n=== Verify ===");
|
|
const verify = await fetch(`${HONO}/api/members/verify`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ famId: fam.id, deviceToken: "dev-token-xyz" }),
|
|
});
|
|
const verifyData = await verify.json();
|
|
console.log("Verify:", JSON.stringify(verifyData, null, 2));
|
|
}
|
|
|
|
main().catch(console.error);
|