Would I Still Use T3's next-auth Setup

Hello everyone I'm trying to figure out if the t3 next-auth setup would be used in my use case scenario. Im trying to create a web app that requires no sign in or log in. The users of the site would just go onto the website and use it to buy something and get an order then thats it, no log in required. I assume that a session is required for this to save their order data just in case they accidentally close the window, other than that I would like the order data to be deleted with the session. Im not actually creating users and saving them. Im simply storing order data on the session. Would the t3 next-auth setup be used in this case?
5 Replies
Samathingamajig
sounds like you should use a different session library since that's not what nextauth is intended to do i'm not even sure if you can store data with nextauth before they have an account
LUNA
LUNA3y ago
Yea I figured this would be the case, I was previously building the app in express where I was just using the express-session package, but I really wanted to learn t3.
Samathingamajig
you can use t3 without next-auth its one of the optional things
LUNA
LUNA3y ago
Yea i'm going to explore that, I was just hoping I could use the full t3 stack for my project Im looking into iron session
esponges
esponges3y ago
Why don't you create a table where you store the user data from next-auth and use this data for the order creation? I made a logbook table whenever the user authenticated with the signIn callback in authOptions
// [...nextauth].ts
export const authOptions: NextAuthOptions = {
// Include user.id on session
callbacks: {
session({ session, user }) {
if (session.user) {
session.user.id = user.id;
}
return session;
},
// register user in logbook when they log in
async signIn({ user, account, profile, email, credentials }) {
try {
await prisma.logbook.create({
data: {
name: user.name,
email: user.email,
lastLogin: new Date(),
},
});
} catch (e) {
console.log("error login logBook data :", e);
}
return true;
},
},
// [...nextauth].ts
export const authOptions: NextAuthOptions = {
// Include user.id on session
callbacks: {
session({ session, user }) {
if (session.user) {
session.user.id = user.id;
}
return session;
},
// register user in logbook when they log in
async signIn({ user, account, profile, email, credentials }) {
try {
await prisma.logbook.create({
data: {
name: user.name,
email: user.email,
lastLogin: new Date(),
},
});
} catch (e) {
console.log("error login logBook data :", e);
}
return true;
},
},
Want results from more Discord servers?
Add your server