(
{
request,
redirectTo = '/',
}: {
request: Request
redirectTo?: string
},
responseInit?: ResponseInit,
)
| 183 | } |
| 184 | |
| 185 | export async function logout( |
| 186 | { |
| 187 | request, |
| 188 | redirectTo = '/', |
| 189 | }: { |
| 190 | request: Request |
| 191 | redirectTo?: string |
| 192 | }, |
| 193 | responseInit?: ResponseInit, |
| 194 | ) { |
| 195 | const authSession = await authSessionStorage.getSession( |
| 196 | request.headers.get('cookie'), |
| 197 | ) |
| 198 | const sessionId = authSession.get(sessionKey) |
| 199 | // if this fails, we still need to delete the session from the user's browser |
| 200 | // and it doesn't do any harm staying in the db anyway. |
| 201 | if (sessionId) { |
| 202 | // the .catch is important because that's what triggers the query. |
| 203 | // learn more about PrismaPromise: https://www.prisma.io/docs/orm/reference/prisma-client-reference#prismapromise-behavior |
| 204 | void prisma.session.deleteMany({ where: { id: sessionId } }).catch(() => {}) |
| 205 | } |
| 206 | throw redirect(safeRedirect(redirectTo), { |
| 207 | ...responseInit, |
| 208 | headers: combineHeaders( |
| 209 | { 'set-cookie': await authSessionStorage.destroySession(authSession) }, |
| 210 | responseInit?.headers, |
| 211 | ), |
| 212 | }) |
| 213 | } |
| 214 | |
| 215 | export async function getPasswordHash(password: string) { |
| 216 | const hash = await bcrypt.hash(password, 10) |
no test coverage detected