2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ローカル環境にSafariでログインしてもトークンが保持されない

Posted at

事象

開発中のWebサービスのローカル環境にSafariでログインしても、アクセストークンとリフレッシュトークンが保持されませんでした!

対処法

どうやら以下のsecure属性に原因があったようです!

secure: true
http間のクッキーの送信を許容しない!

secure: false
http間のクッキーの送信も許容する!

SafariもChromeもhttp接続でしたが、Chromeならトークンが保持されるのは、
開発者の利便性を考慮し、localhostではsecure属性を無視してくれるからのようです!

auth.ts
case "POST":
  const token = JSON.parse(req.body) as Tokens;
  const options: CookieSerializeOptions = {
    path: "/",
    maxAge: 30 * 24 * 60 * 60,
    httpOnly: true,
    secure: true
    sameSite: true,
  };
  res.setHeader(
    "Set-Cookie",
    serialize(Object.keys(token)[0], Object.values(token)[0], options),
  );
  res.status(200).json({});
  break;

自らの備忘録のために投稿してますが、なにかお役に立てましたら幸いです!:clap:
また、なにか間違ってましたらご指摘いただけますと幸いです!:pray:

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?