Skip to content

Commit

Permalink
fix: already existing session response is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasDeco committed Aug 13, 2024
1 parent fe0e448 commit 271aaf3
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/indexer/src/endpoints/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,27 @@ export async function authPut(req: Request, res: Response) {
);

const existingSession = await checkExistingSession(pubKey);
if (existingSession) {
return res.status(409).json({
error: "Session already exists and has not expired.",
if (existingSession && existingSession.expiresAt) {
const token = jwt.sign(
{
sub: existingSession.id,
pubKey,
iat: Math.floor(existingSession.createdAt.getTime() / 1000), // Issued at
exp: Math.floor(existingSession.expiresAt?.getTime() / 1000), // Expiry time
"https://hasura.io/jwt/claims": {
"x-hasura-default-role": "user",
"x-hasura-allowed-roles": ["user"],
"x-hasura-user-id": pubKey,
},
},
PRIVATE_KEY, // Use the RSA private key to sign the JWT
{ algorithm: "RS256" } // Specify the RS256 algorithm
);
return res.status(200).json({
message: "Session already exists and has not expired.",
sessionId: existingSession.id,
expiryTime,
token, // Include the JWT in the response
});
}

Expand Down

0 comments on commit 271aaf3

Please sign in to comment.