0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

セッション情報の取り扱い方

0
Posted at

記事の概要

アプリにおけるセッション情報の取り扱い方をざっくりとまとめました(勉強のアウトプット用)
通販サイトのカードの情報をセッションが残っている限り保持したい場合を例としています。

前提:テーブル

①ユーザー情報TBL

UserTBL

user_id | email             | password_hash
------------------------------------------------
u001    | aaa@example.com   | xxxxx

②セッション情報TBL

session_id | user_id | expire   | cart_number
------------------------------------------------
aab123     | u001    | 20260606 | 3

③カート情報TBL

user_id    | cart_product_id
------------------------------------------
aab123     |   A1005
aab123     |   B1005

ログイン時(セッション情報がまだ何もない状態)

①ユーザーが以下を入力
メールアドレス: aaa@example.com
パスワード: xxxxxx
②アプリ側が入力情報とユーザー情報TBLのemail・password_hashを突合。(passwordは素のままでなくハッシュ化する。)
③認証成功ならsession_idを発行。ブラウザはCookieにsession_idを保持。
④商品をカートに入れる

次回ログイン時

①パスワード・メールアドレスをアプリに渡す前にCookieのセッション情報を伝達する。
②アプリ側がsession_idをキーにセッション情報TBLを検索。見つかった場合&現時点でexpireより日付が前の場合はそのままログインできる。そしてカート情報TBLの中身を返す

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?