-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4da00b2
commit 7cbb36c
Showing
10 changed files
with
85 additions
and
19 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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const sessionLifeTimeHours = process.env.SESSION_LIFETIME_HOURS | ||
? parseInt(process.env.SESSION_LIFETIME_HOURS) | ||
: 0 |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
|
||
export const prismaClient = new PrismaClient() |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Session } from '@prisma/client' | ||
import { prismaClient } from './prisma-client' | ||
import { v4 as uuid } from 'uuid' | ||
import { Dayjs } from 'dayjs' | ||
|
||
export async function createSession({ | ||
userId, | ||
expiredAt, | ||
}: { | ||
userId: string | ||
expiredAt: Dayjs | ||
}): Promise<Session> { | ||
const id = uuid() | ||
return await prismaClient.session.create({ | ||
data: { id, user_id: userId, expired_at: expiredAt.toDate() }, | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import dayjs from 'dayjs' | ||
import { google, SessionService, StartSessionResponse } from '../../generated' | ||
import { sessionLifeTimeHours } from '../constant' | ||
import { createSession } from '../database/session' | ||
import { GrpcServer } from './type' | ||
|
||
export const sessionService: GrpcServer<SessionService> = { | ||
async startSession({ request }, callback) { | ||
const session = await createSession({ | ||
userId: request.userId, | ||
expiredAt: dayjs().add(sessionLifeTimeHours, 'hour'), | ||
}) | ||
|
||
callback( | ||
null, | ||
StartSessionResponse.create({ | ||
session: { | ||
sessionId: session.id, | ||
userId: session.user_id, | ||
expiredAt: google.protobuf.Timestamp.create({ | ||
seconds: session.expired_at.getTime() / 1000, | ||
}), | ||
}, | ||
}) | ||
) | ||
}, | ||
getSession({ request }, callback) { | ||
// not implemented yet | ||
}, | ||
} |
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