Default
Default
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Default on 7/24/2024 in #questions
Session user id does not get added to session
My code:
import { PrismaAdapter } from '@auth/prisma-adapter';
import { type DefaultSession, type NextAuthOptions, getServerSession } from 'next-auth';
import type { Adapter } from 'next-auth/adapters';
import DiscordProvider from 'next-auth/providers/discord';

import { env } from 'env';
import { db } from 'server/db';

/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
* object and keep type safety.
*
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
*/
declare module 'next-auth' {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
// role: UserRole;
} & DefaultSession['user'];
}

// interface User {
// // ...other properties
// // role: UserRole;
// }
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/
export const authOptions: NextAuthOptions = {
session: {
strategy: 'jwt',
},
callbacks: {
session: ({ session, token }) => ({
...session,
user: {
...session.user,
id: token.sub,
},
}),
},
adapter: PrismaAdapter(db) as Adapter,
providers: [
DiscordProvider({
clientId: env.DISCORD_CLIENT_ID,
clientSecret: env.DISCORD_CLIENT_SECRET,
}),
],
pages: {
signIn: '/auth/login',
},
};

/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = () => getServerSession(authOptions);
import { PrismaAdapter } from '@auth/prisma-adapter';
import { type DefaultSession, type NextAuthOptions, getServerSession } from 'next-auth';
import type { Adapter } from 'next-auth/adapters';
import DiscordProvider from 'next-auth/providers/discord';

import { env } from 'env';
import { db } from 'server/db';

/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
* object and keep type safety.
*
* @see https://next-auth.js.org/getting-started/typescript#module-augmentation
*/
declare module 'next-auth' {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
// role: UserRole;
} & DefaultSession['user'];
}

// interface User {
// // ...other properties
// // role: UserRole;
// }
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/
export const authOptions: NextAuthOptions = {
session: {
strategy: 'jwt',
},
callbacks: {
session: ({ session, token }) => ({
...session,
user: {
...session.user,
id: token.sub,
},
}),
},
adapter: PrismaAdapter(db) as Adapter,
providers: [
DiscordProvider({
clientId: env.DISCORD_CLIENT_ID,
clientSecret: env.DISCORD_CLIENT_SECRET,
}),
],
pages: {
signIn: '/auth/login',
},
};

/**
* Wrapper for `getServerSession` so that you don't need to import the `authOptions` in every file.
*
* @see https://next-auth.js.org/configuration/nextjs
*/
export const getServerAuthSession = () => getServerSession(authOptions);
3 replies
DIAdiscord.js - Imagine an app
Created by Default on 9/14/2023 in #djs-questions
Bot presence not updating
code:
client.user?.setPresence({
status,
activities: [
{
name: client.config.botPresence.activity.replacer({ totalPlayers, totalMaxPlayers, totalServers }),
type,
},
],
});
console.log(client.user?.presence);
client.user?.setPresence({
status,
activities: [
{
name: client.config.botPresence.activity.replacer({ totalPlayers, totalMaxPlayers, totalServers }),
type,
},
],
});
console.log(client.user?.presence);
console:
ClientPresence {
userId: null,
guild: null,
status: 'Online',
activities: [
Activity {
name: '0 players on 2 servers',
type: 'Watching',
url: null,
details: null,
state: null,
applicationId: null,
timestamps: null,
party: null,
assets: null,
flags: [ActivityFlagsBitField],
emoji: null,
buttons: [],
createdTimestamp: undefined
}
],
clientStatus: null
}
ClientPresence {
userId: null,
guild: null,
status: 'Online',
activities: [
Activity {
name: '0 players on 2 servers',
type: 'Watching',
url: null,
details: null,
state: null,
applicationId: null,
timestamps: null,
party: null,
assets: null,
flags: [ActivityFlagsBitField],
emoji: null,
buttons: [],
createdTimestamp: undefined
}
],
clientStatus: null
}
For some reason my bot does not have any status or custom presence. anyone know why?
16 replies
DIAdiscord.js - Imagine an app
Created by Default on 9/2/2023 in #djs-questions
InteractionAlreadyReplied even with catch
code:
await interaction.deferReply({ ephemeral: config.commands.leaderboard.ephemeral }).catch(() => {});
await interaction.deferReply({ ephemeral: config.commands.leaderboard.ephemeral }).catch(() => {});
When i use the leaderboard command i sometimes get this error:
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ChatInputCommandInteraction.reply (C:\Users\Administrator\Downloads\StaticsBot-2.0.1 from dm\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:102:46)
at Object.run (C:\Users\Administrator\Downloads\StaticsBot-2.0.1 from dm\modules\commands\leaderboards.js:102:46)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'InteractionAlreadyReplied'
} Unhandled Rejection
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ChatInputCommandInteraction.reply (C:\Users\Administrator\Downloads\StaticsBot-2.0.1 from dm\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:102:46)
at Object.run (C:\Users\Administrator\Downloads\StaticsBot-2.0.1 from dm\modules\commands\leaderboards.js:102:46)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'InteractionAlreadyReplied'
} Unhandled Rejection
How can this error still happen even with a catch?
2 replies
DIAdiscord.js - Imagine an app
Created by Default on 3/31/2023 in #djs-questions
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'file-type'
I get this error and dont know how to solve this.
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'file-type' imported from C:\Users\Administrator\Desktop\EliteArk Main Ticketbot 3\node_modules@discordjs\rest\dist\index.js
Did you mean to import file-type/index.js?
at new NodeError (node:internal/errors:372:5)
at packageResolve (node:internal/modules/esm/resolve:954:9)
at moduleResolve (node:internal/modules/esm/resolve:1003:20)
at defaultResolve (node:internal/modules/esm/resolve:1218:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
at ESMLoader.import (node:internal/modules/esm/loader:380:22)
at importModuleDynamically (node:internal/modules/cjs/loader:1043:29)
at importModuleDynamicallyWrapper (node:internal/vm/module:437:21)
at importModuleDynamically (node:vm:381:46) {
code: 'ERR_MODULE_NOT_FOUND'
} Unhandled Rejection at Promise
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'file-type' imported from C:\Users\Administrator\Desktop\EliteArk Main Ticketbot 3\node_modules@discordjs\rest\dist\index.js
Did you mean to import file-type/index.js?
at new NodeError (node:internal/errors:372:5)
at packageResolve (node:internal/modules/esm/resolve:954:9)
at moduleResolve (node:internal/modules/esm/resolve:1003:20)
at defaultResolve (node:internal/modules/esm/resolve:1218:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:580:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:294:18)
at ESMLoader.import (node:internal/modules/esm/loader:380:22)
at importModuleDynamically (node:internal/modules/cjs/loader:1043:29)
at importModuleDynamicallyWrapper (node:internal/vm/module:437:21)
at importModuleDynamically (node:vm:381:46) {
code: 'ERR_MODULE_NOT_FOUND'
} Unhandled Rejection at Promise
14 replies
DIAdiscord.js - Imagine an app
Created by Default on 12/22/2022 in #djs-questions
how to send webhooks in forum posts?
how to send webhook messages in forum posts #github-updates
4 replies
DIAdiscord.js - Imagine an app
Created by Default on 12/9/2022 in #djs-questions
How to check if all shards are online
I am trying to make a system that sends a message to a server once all shards are online, how can i see if all shards are ready?
4 replies
DIAdiscord.js - Imagine an app
Created by Default on 11/27/2022 in #djs-questions
How to only cache the guilds
how i can i only cache guilds?
16 replies