Closed trnc-ck closed 7 months ago
+1 on this. Also using PG (via Supabase).
Getting an oAuth redir loop.
@trnc-ck any luck on your end?
Sorry, I've been stuck on another project but I will try to take a look over the next couple of days. Been meaning to add in some example code for postgres (on prisma or something). I'll check it out
@ozzyonfire sure. here's the session storage. the "content" col is a json field. from the data side everything seems okay, also the logs.
import { Session } from "@shopify/shopify-api";
const DB_NAME = 'shopify-apps';
const apiKey = process.env.SHOPIFY_API_KEY || '';
import prisma from "./prisma";
export async function storeSession(session: Session) {
try {
await prisma.session.upsert({
where: { id: session.id },
update: {
content: session,
shop: session.shop,
},
create: {
id: session.id,
content: session,
shop: session.shop,
},
});
return true;
} catch (err) {
console.log(err);
return false;
}
}
export async function loadSession(id: string) {
const record = await prisma.session.findUnique({ where: { id } });
if (record) {
return record.content;
} else {
return undefined;
}
}
export async function deleteSession(id: string) {
try {
await prisma.session.deleteMany({ where: { id } });
return true;
} catch (err) {
console.log(err);
return false;
}
}
export async function deleteSessions(ids: string[]) {
try {
await prisma.session.deleteMany({
where: {
id: {
in: ids
}
}
});
return true;
} catch (err) {
console.log(err);
return false;
}
}
// export async function cleanUpSession(shop: string, accessToken: string) {
// try {
// await db.collection('sessions').deleteOne({ shop, accessToken });
// return true;
// } catch (err) {
// console.log(err);
// return false;
// }
// }
export async function findSessionsByShop(shop: string) {
const records = await prisma.session.findMany({ where: { shop: shop } });
let sessions = []
records.forEach(element => {
sessions.push(element.content)
})
if (sessions) {
return sessions;
}
return [];
}
I just updated a bunch of stuff on the repo.
Now you will find a prisma example that uses postgres. I was able to get it running smoothly in my dev environment. Let me know if anything comes up
Thx @ozzyonfire for your effort. Will check it out!
hey,
we tried out your boilerplate and changed the session storage to postgres, by refactoring just the loading/creating/finding sessions in the db. this seems to work, as it can write sessions and read them. problem is:
after being redirect by the shopify oauth screen to / it keeps opening new windows. here's the console log:
any idea? can't believe that this occurs because of the switch to postgres.