mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 01:32:06 +10:00
wip
This commit is contained in:
22
packages/auth/server/lib/utils/authorizer.ts
Normal file
22
packages/auth/server/lib/utils/authorizer.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import type { Context } from 'hono';
|
||||
|
||||
import type { HonoAuthContext } from '../../types/context';
|
||||
import { createSession, generateSessionToken } from '../session/session';
|
||||
import { setSessionCookie } from '../session/session-cookies';
|
||||
|
||||
type AuthorizeUser = {
|
||||
userId: number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles creating a session.
|
||||
*/
|
||||
export const onAuthorize = async (user: AuthorizeUser, c: Context<HonoAuthContext>) => {
|
||||
const metadata = c.get('requestMetadata');
|
||||
|
||||
const sessionToken = generateSessionToken();
|
||||
|
||||
await createSession(sessionToken, user.userId, metadata);
|
||||
|
||||
await setSessionCookie(c, sessionToken);
|
||||
};
|
||||
Reference in New Issue
Block a user