Skip to content

Commit dfa77e8

Browse files
committed
fix: Proper type declaration
1 parent 27cea6b commit dfa77e8

File tree

6 files changed

+76
-7
lines changed

6 files changed

+76
-7
lines changed

build.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { $ } from "bun"
1+
import { $ } from "bun";
22

3-
await $`tsc`
4-
await $`cp types/index.d.ts dist/index.d.ts`
3+
await $`tsc`;
4+
await $`mkdir -p dist/types`;
5+
await $`cp types/*.d.ts dist/types/`;
56

67
console.log("Build completed successfully!");

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,28 @@
2929
"dependencies": {
3030
"jsonwebtoken": "^9.0.2",
3131
"next": "^15.3.2"
32+
},
33+
"exports": {
34+
".": {
35+
"import": "./dist/index.js",
36+
"require": "./dist/index.js",
37+
"types": "./dist/types/index.d.ts"
38+
},
39+
"./redirect": {
40+
"import": "./dist/redirect.js",
41+
"require": "./dist/redirect.js",
42+
"types": "./dist/types/redirect.d.ts"
43+
},
44+
"./server-actions": {
45+
"import": "./dist/server-actions.js",
46+
"require": "./dist/server-actions.js",
47+
"types": "./dist/types/server-actions.d.ts"
48+
}
49+
},
50+
"typesVersions": {
51+
"*": {
52+
"redirect": ["dist/types/redirect.d.ts"],
53+
"server-actions": ["dist/types/server-actions.d.ts"]
54+
}
3255
}
3356
}

src/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,23 @@ export function setup(config: Config) {
3333
}
3434
}
3535
if (globalConfig) {
36-
console.warn("Global config is already set. Overwriting existing config.");
36+
console.warn(
37+
"Global config is already set. Overwriting existing config.",
38+
);
3739
}
3840
globalConfig = {
39-
clientId: config.clientId ?? process.env.AUTH_DISCORD_ID ?? (() => { throw new Error("clientId is required"); })(),
40-
clientSecret: config.clientSecret ?? process.env.AUTH_DISCORD_SECRET ?? (() => { throw new Error("clientSecret is required"); })(),
41+
clientId:
42+
config.clientId ??
43+
process.env.AUTH_DISCORD_ID ??
44+
(() => {
45+
throw new Error("clientId is required");
46+
})(),
47+
clientSecret:
48+
config.clientSecret ??
49+
process.env.AUTH_DISCORD_SECRET ??
50+
(() => {
51+
throw new Error("clientSecret is required");
52+
})(),
4153
scopes: config.scopes ?? ["identify", "email"],
4254
redirectUri: config.redirectUri,
4355
jwtSecret: config.jwtSecret,

types/index.d.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
declare module '@mikandev/next-discord-auth';
1+
export interface Session {
2+
user: {
3+
id: string;
4+
name: string;
5+
email?: string;
6+
avatar: string;
7+
};
8+
expires: string;
9+
accessToken?: string;
10+
}
11+
12+
export interface Config {
13+
clientId: string;
14+
clientSecret: string;
15+
scopes: string[];
16+
redirectUri: string;
17+
jwtSecret: string;
18+
}
19+
20+
export function setup(config: Config): void;
21+
export function getGlobalConfig(): Config;

types/redirect.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { NextRequest, NextResponse } from "next/server";
2+
3+
export declare function handleRedirect(
4+
req: NextRequest,
5+
): Promise<NextResponse | void>;

types/server-actions.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { NextRequest, NextResponse } from "next/server";
2+
import type { Session } from "./index";
3+
4+
export declare function getSession(req: NextRequest): Promise<Session | null>;
5+
6+
export declare function signIn(req: NextRequest): Promise<NextResponse>;
7+
8+
export declare function signOut(req: NextRequest): Promise<NextResponse>;

0 commit comments

Comments
 (0)