Skip to content

Commit

Permalink
make logout delete the session
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Aug 3, 2023
1 parent 23c6411 commit a97c003
Show file tree
Hide file tree
Showing 43 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(userIdKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(userIdKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ export async function signup({
export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
// 🐨 this should be sessionKey instead of userIdKey
const sessionId = cookieSession.get(userIdKey)
await prisma.session.delete({ where: { id: sessionId } })
// 🐨 this should be sessionKey instead of userIdKey
cookieSession.unset(userIdKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
2 changes: 2 additions & 0 deletions exercises/10.email/01.problem.resend/app/utils/auth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
2 changes: 2 additions & 0 deletions exercises/10.email/02.problem.mocks/app/utils/auth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
2 changes: 2 additions & 0 deletions exercises/10.email/02.solution.mocks/app/utils/auth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
2 changes: 2 additions & 0 deletions exercises/10.email/03.problem.send/app/utils/auth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
2 changes: 2 additions & 0 deletions exercises/10.email/03.solution.send/app/utils/auth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export async function signup({

export async function logout(request: Request) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect('/', {
headers: { 'set-cookie': await commitSession(cookieSession) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export async function logout(
responseInit?: ResponseInit,
) {
const cookieSession = await getSession(request.headers.get('cookie'))
const sessionId = cookieSession.get(sessionKey)
await prisma.session.delete({ where: { id: sessionId } })
cookieSession.unset(sessionKey)
throw redirect(safeRedirect(redirectTo), {
...responseInit,
Expand Down

0 comments on commit a97c003

Please sign in to comment.