Firebase Auth-ConfirmPasswordReset,如何从URL中获取oobcode以通过thorugh函数? [英] Firebase Auth - ConfirmPasswordReset, how to grab oobcode from URL to pass thorugh function?

查看:65
本文介绍了Firebase Auth-ConfirmPasswordReset,如何从URL中获取oobcode以通过thorugh函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Firebase身份验证在我的网站上实施重置密码页面.我收到了发送电子邮件以重置密码页面的信息.现在,据我了解,您会收到一封电子邮件,其中包含您需要单击的链接,并且在该电子邮件中,将需要一个用于重置密码的代码.现在,我对如何从url中获取所说的代码并已经在现场为用户显示代码不知所措.电子邮件正文中是否可以包含该代码,并且用户可以输入该代码?如果没有,我如何从URL中获取代码并为用户输入代码,以便用户只能输入密码?我的网站正在使用vue,这就是我到目前为止所拥有的

I'm trying to implement a reset password Page on my website using firebase auth. I got the send email to reset password page working. Now from what I understand you get an email with a link that you need to click and on this email there will be a code that is needed to reset the password. Now I'm at a loss on how to grab said code from the url and already display it for the user on the field. Is it possible to have the code come in the body of the email and have the user input the code? If not, how do I grab the code from the url and input it for the user so the user can only input the password? My website is using vue and this is what I have so far

<template>
  <div class="container">
    <h3>reset pw page</h3>
    <div class="row">
      <form @submit.prevent="ResetPw()" class="col s12">
        <div class="row">
          <div class="input-field col s12">
            <input type="password" id="password" v-model="password" />
            <label>Password</label>
          </div>
        </div>
        <div class="row">
          <div class="input-field col s12">
            <input type="text" id="code" v-model="code" />
            <label>Code</label>
          </div>
        </div>
        <button type="submit" class="btn">Submit</button>
      </form>
    </div>
  </div>
</template>

<script>
import firebase from "firebase/app";
export default {
  data() {
    return {
      password: "",
      code: ""
    };
  },
  methods: {
    ResetPw() {
      firebase
        .auth()
        .confirmPasswordReset(this.code, this.password)
        .then(() => {
          console.log(`Password Changed!`);
        })
        .catch(err => console.log(err));
    }
  }
};
</script>

我想我已经完成了所有事情,我只需要了解如何从链接 https://my-project.firebaseapp.com/__/auth/action?mode= & oobCode =

I think I got everything done, I just need to understand how to grab the oobcode from the link https://my-project.firebaseapp.com/__/auth/action?mode=&oobCode=

推荐答案

如果您使用react-router,它将不再解析查询,但可以通过location.search

If you are using react-router, it does not parse the query any more, but you can access it via location.search

const params = new URLSearchParams(this.props.location.search);
const code = params.get('oobCode')
const email = await firebase.auth().verifyPasswordResetCode(code)

或者,您可以使用新的 URLSearchParams(window.location.pathname)

Alternatively, instead of using this.props.location.search, you can do new URLSearchParams(window.location.pathname)

这篇关于Firebase Auth-ConfirmPasswordReset,如何从URL中获取oobcode以通过thorugh函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆