Helix
Helix
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Helix on 7/28/2024 in #questions
Lucia Auth Question
I have been having some trouble setting up a deep link redirect callback for Lucia Auth, does anyone have any examples or help they could provide? My setup is just the basic lucia auth setup with the email/password login. Nothing has been changed. https://gist.github.com/cnbrown04/ba61a256dcbc23122b99ea0964567fe1
2 replies
TTCTheo's Typesafe Cult
Created by Helix on 7/25/2024 in #questions
Auth Library Suggestions
I’m currently developing a iOS app in Swift and I’m trying to use a WebAuth session, however it seems nextauth does not work with a native swift app. Any suggestions on what to use instead?
10 replies
TTCTheo's Typesafe Cult
Created by Helix on 7/24/2024 in #questions
NextAuth Callbacks
I'm currently trying to implement my nextauth instance in an ios app, but im having some trouble implementing callbacks that pass the session id and user id/token back to the app. I'm currently just using the credentials authOption, but if anyone could point me in the right direction that would be great. Thanks!
export const authOptions: NextAuthOptions = {
callbacks: {
jwt: async ({ token, user }) => {
if (user) {
token.id = user.id;
token.email = user.email;
}

return token;
},
session: ({ session, token, user }) => ({
...session,
user: {
...session.user,
id: token.id || user.id,
},
}),
},
adapter: PrismaAdapter(db) as Adapter,
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "Username",
type: "text",
placeholder: "jose@gmail.com",
},
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
if (!credentials?.email || !credentials?.password) return null;

const user = await db.user.findUnique({
where: {
email: credentials.email.toLowerCase(),
},
});

if (!user?.passwordHash) return null;

const passwordsMatch = await bcrypt.compare(
credentials.password,
user.passwordHash,
);

if (!passwordsMatch) return null;

return user;
},
}),
],
};
export const authOptions: NextAuthOptions = {
callbacks: {
jwt: async ({ token, user }) => {
if (user) {
token.id = user.id;
token.email = user.email;
}

return token;
},
session: ({ session, token, user }) => ({
...session,
user: {
...session.user,
id: token.id || user.id,
},
}),
},
adapter: PrismaAdapter(db) as Adapter,
session: {
strategy: "jwt",
},
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
email: {
label: "Username",
type: "text",
placeholder: "jose@gmail.com",
},
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
if (!credentials?.email || !credentials?.password) return null;

const user = await db.user.findUnique({
where: {
email: credentials.email.toLowerCase(),
},
});

if (!user?.passwordHash) return null;

const passwordsMatch = await bcrypt.compare(
credentials.password,
user.passwordHash,
);

if (!passwordsMatch) return null;

return user;
},
}),
],
};
I haven't changed much from the base t3 stack app besides adding the passwordHash functionalities.
9 replies