-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stable public and private key generation
- Loading branch information
Showing
5 changed files
with
23 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
import assert from 'assert'; | ||
import type { UserEntity } from 'common/types/user'; | ||
import { userQuery } from 'domain/user/repository/userQuery'; | ||
import type { JWT_PROP_NAME } from 'service/constants'; | ||
import { prismaClient } from 'service/prismaClient'; | ||
import type { IdTokenJwt } from 'service/types'; | ||
import { defineHooks } from './$relay'; | ||
|
||
export type AdditionalRequest = { | ||
[Key in typeof JWT_PROP_NAME]: IdTokenJwt; | ||
} & { user: UserEntity }; | ||
export type AdditionalRequest = { user: UserEntity }; | ||
|
||
export default defineHooks(() => ({ | ||
onRequest: async (req, res) => { | ||
try { | ||
await req.jwtVerify({ onlyCookie: true }); | ||
} catch (e) { | ||
res.status(401).send((e as Error).message); | ||
return; | ||
} | ||
|
||
assert(req.idToken); | ||
|
||
req.user = await userQuery.findById(prismaClient, req.idToken.sub); | ||
req.user = await req | ||
.jwtVerify<IdTokenJwt>({ onlyCookie: true }) | ||
.then((idToken) => userQuery.findById(prismaClient, idToken.sub)) | ||
.catch((e) => res.status(401).send((e as Error).message)); | ||
}, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
export const COOKIE_NAME = 'session'; | ||
|
||
export const JWT_PROP_NAME = 'idToken'; | ||
|
||
export const EXPIRES_SEC = 3600; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters