Skip to content

Commit

Permalink
types fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mluena committed Oct 17, 2024
1 parent bc7f844 commit 3186243
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
43 changes: 22 additions & 21 deletions client/src/app/api/auth/[...nextauth]/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,35 @@ export const authOptions: AuthOptions = {
return p;
}
}, {});
const decoded = jwtDecode(token.apiToken);

const sessionToken = session.sessionToken ?? token;
const decoded = jwtDecode(token.apiToken);

if (sessionToken) {
const now = new Date().getTime();
const exp = (decoded.iat * 1000) + (SESSION_MAX_AGE * 1000);
const sessionToken = session.sessionToken ?? token;

if (now < exp) {
return ({
...session,
user: sanitizedToken,
apiToken: token.apiToken,
});
} else {
return ({
...session,
user: sanitizedToken,
error: "ExpiredTokenError",
});
}
}
if (sessionToken && decoded.iat) {
const now = new Date().getTime();
const exp = decoded.iat * 1000 + SESSION_MAX_AGE * 1000;

return ({
if (now < exp) {
return {
...session,
user: sanitizedToken,
apiToken: token.apiToken,
})
};
} else {
return {
...session,
user: sanitizedToken,
error: "ExpiredTokenError",
};
}
}

return {
...session,
user: sanitizedToken,
apiToken: token.apiToken,
};
},
async jwt({ token, user }) {
if (typeof user !== "undefined") {
Expand Down
14 changes: 7 additions & 7 deletions client/src/types/next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import { JWT } from "next-auth/jwt"
import { JWT } from "next-auth/jwt";
import "next-auth";

declare module "next-auth" {
Expand All @@ -18,13 +17,14 @@ declare module "next-auth" {
apiToken: string;
user: User;
error: string;
sessionToken: JWT;
}
}


declare module "next-auth/jwt" {
interface JWT {
exp: number;
iat: number;
}
interface JWT {
exp: number;
iat: number;
apiToken: string;
}
}

0 comments on commit 3186243

Please sign in to comment.