0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Vue3]Supabaseで簡単にMFAログインを実装する

Posted at

TL;DR

実装したコード

<script setup lang="ts">
import { supabase } from '@/utils/supabase';

const targetEmail = 'ユーザーが入力した自分のメールアドレス';
const redirectURL = 'リンクをクリックするとリダイレクトされるページ';

const login = async () => {
  try {
    const { error } = await supabase.auth.signInWithOtp({
      email: targetEmail,
      options: {
        shouldCreateUser: false,
        emailRedirectTo: redirectURL,
      },
    });
    
    alert('入力したメールアドレスにログイン確認メールを送信しました.');
    router.push('/');
  } catch (error) {
    alert(error.message)
  }
};
</script>

Magic Linkの編集

Supabseメニューの「Authentications」

スクリーンショット 2024-06-30 16.08.46(小).jpeg

「Email Templates」-> Magic LinkでHTMLメールが修正できる。

スクリーンショット 2024-06-30 16.08.58(小).jpeg

終わりに

結局公式ドキュメントに書いてある通りではある。
しかし普通に調べているとすぐ見つからなかった。React向けのページは多いけれども...

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?