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;
      },
    }),
  ],
};
I haven't changed much from the base t3 stack app besides adding the passwordHash functionalities.
Was this page helpful?