MCPcopy
hub / github.com/epicweb-dev/epic-stack / logout

Function logout

app/utils/auth.server.ts:185–213  ·  view source on GitHub ↗
(
	{
		request,
		redirectTo = '/',
	}: {
		request: Request
		redirectTo?: string
	},
	responseInit?: ResponseInit,
)

Source from the content-addressed store, hash-verified

183}
184
185export 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
215export async function getPasswordHash(password: string) {
216 const hash = await bcrypt.hash(password, 10)

Callers 3

loaderFunction · 0.90
loaderFunction · 0.90
actionFunction · 0.90

Calls 1

combineHeadersFunction · 0.90

Tested by

no test coverage detected