How to install firebase properly? - firebase

I am working on a login system in vue, this is my code for now:
<template>
<div>
<input type="email" placeholder="Email" v-model="email" />
<input type="password" placeholder="Password" v-model="password" />
<button>Login</button>
<p>Need an account?<router-link to="/signup">Sign Up</router-link></p>
</div>
</template>
<script>
import firebase from 'firebase'
export default {
name: "Login",
data() {
return {
email: "",
password: "",
};
},
methods: {
Login() {
// Log the user in
firebase
.auth()
.signInWithEmailAndPassword(this.email, this.password)
.then(
(user) => {
console.log(user.data);
},
(err) => {
alert(err);
}
);
},
},
};
</script>
<style>
</style>
The problem is that I get an error when I try to run it, this is the error:
This dependency was not found:
* firebase in ./node_modules/cache-loader/dist/cjs.js??ref--13-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref--1-0!./node_modules/vue-loader-v16/dist??ref--1-1!./src/views/Login.vue?vue&type=script&lang=js
To install it, you can run: npm install --save firebase
I tried installing firebase a couple of times, but I keep getting the same error.
If anyone knows a solution, thank you very much!

To install firebase properly, you have to change the version:
npm remove firebase
npm add firebase#^8.10.0

Welcome, what command are you running to install Firebase? The error says to use npm install --save firebase, are you using that command? Try the commandnpm install Firebase to try install Firebase. Are you using "Cloud Shell" to deploy your code?
I used the following documentation to learn about the basics of Firebase [1}
[1} https://firebase.google.com/docs/web/setup
and this lab is also very useful [2]
[1] https://firebase.google.com/codelabs/firebase-web#0

Related

React Hydration Error from basic Supabase auth implementation

After implementing the basic authentication experience from supabase, I'm trying to create a simple page that's only available to authenticated users and shows their user data.
I'm consistently faced with a React Hydration Error despite implementing exactly what the docs say.
The error occurs when logged in. When logged out I'm successfully routed to /wip
Here's my simple page code.
import {NextPage} from 'next';
import styles from '../styles/Home.module.css';
import {withPageAuth} from '#supabase/auth-helpers-nextjs';
export const getServerSideProps = withPageAuth({redirectTo: '/wip'});
const Profile: NextPage = ({user}) => {
return (
<div className={styles.container}>
<main className={styles.main}>
<h1 className={styles.title}>Welcome back!</h1>
<p>
<pre>{JSON.stringify(user, null, 2)}</pre>
</p>
</main>
</div>
);
};
export default Profile;
Package.json
"dependencies": {
"#supabase/auth-helpers-nextjs": "^0.2.8",
"#supabase/auth-helpers-react": "^0.2.4",
"#supabase/supabase-js": "^1.35.7",
"#supabase/ui": "^0.36.5",
"next": "12.3.1",
"pocketbase": "^0.7.1",
"react": "18.2.0",
"react-dom": "18.2.0"
}

how to fix nextjs prerender error - vercel deployment?

How do I troubleshoot this problem this deployment issue? I am following this tutorial. My node_modules and .next are ignored and not pushed to github. It works locally but can't seem to deploy. I have supplied both the component code as well as the page it's exported on. Let me know if you can see what I am missing.
https://www.youtube.com/watch?v=V4SVNleMitE
deployment errors
Error occurred prerendering page "/components/BlogPosts". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read property 'fields' of undefined
at BlogPosts (/vercel/path0/.next/server/chunks/130.js:39:12)
at d (/vercel/path0/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:33:498)
at bb (/vercel/path0/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:36:16)
at a.b.render (/vercel/path0/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:42:43)
at a.b.read (/vercel/path0/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:41:83)
at Object.exports.renderToString (/vercel/path0/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:52:138)
at Object.renderPage (/vercel/path0/node_modules/next/dist/server/render.js:673:46)
at Object.defaultGetInitialProps (/vercel/path0/node_modules/next/dist/server/render.js:315:51)
at Function.getInitialProps (/vercel/path0/.next/server/pages/_document.js:645:16)
at Object.loadGetInitialProps (/vercel/path0/node_modules/next/dist/shared/lib/utils.js:69:29)
component blog posts
export default function BlogPosts({post }) {
const {title, information,slug , thumbnail} = post.fields
return (
<div>
<div className='container w-50 h-25 mt-4'>
<Image
className='nav'
src={'https:' + thumbnail.fields.file.url}
width={thumbnail.fields.file.details.image.width}
height={thumbnail.fields.file.details.image.height}
/>
</div>
<div>
<div>
<h4 className=''>{title}</h4>
<Link href={'/contentslug/' + slug}>
<a className='btn btn-primary text-white'>Read more</a>
</Link>
</div>
</div>
</div>
)
}
Pages/Posts
import {createClient} from 'contentful'
import BlogPosts from './components/BlogPosts'
import Nav from './components/Nav'
import Logo from './components/Logo'
export async function getStaticProps() {
const client = createClient({
space: process.env.NEXT_PUBLIC_CONTENTFUL_ID,
accessToken: process.env.NEXT_PUBLIC_CONTENTFUL_TOKEN,
})
const res = await client.getEntries({content_type: 'posts'})
return {
props: {
posts: res.items ,
revalidate: 1
}
}
}
export default function Home({posts}) {
console.log(posts);
return (
<div>
<Logo/>
<Nav/>
<div className="container text-center display-5">
{posts.map(post => (
<BlogPosts key={post.sys.id} post={post}/>
))}
</div>
</div>
)
}
You have fields of undefined. this might be caused because of some strange deploying behavior if you are 100% sure your code works.
How to fix (probably):
Build your project locally. if it works, follow the next step
Comment your code in BlogPosts, inside the exported component. The code must work, so your exported component will be empty but working.
Push this code to Vercel.
Uncommit your code. (done at point 2)
Push again.
P.S. this behavior with API is sometimes caused because of API middleware you reworked.

How do I fix the bug: "TypeError: firebase.auth.sendPasswordResetEmail is not a function" in a Vue app with Firebase?

I'm using Vue to create a sign-up/sign-in page by implementing Firebase's client-side authentication system. I've already enabled the email authentication in my Firebase console, and the implementation of signing a user up was a success. However, for some reason, the function firebase.auth.sendPasswordResetEmail() is giving the error TypeError: firebase.auth.sendPasswordResetEmail is not a function in the console. The email I'm using is already present in the Firebase's Users data. The code is from a separate Forgot Your Password page, where I've already imported the relevant JavaScript files (firebase-auth.js, firebase-app.js, and vue.js).
Here's the code I've written:
<section class="columns" id="content">
<div class="column content">
<form #submit.prevent="sendPasswordResetEmail">
<p>Please enter your e-mail if you've forgotten your password:</p>
<input type="email" name="email" v-model="email"><br /><br />
<button type="submit">Submit</button>
</form>
</div>
</section>
<script>
const config = {
//Removed the values from config.
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
};
firebase.initializeApp(config);
new Vue({
el: '#content',
data: {
email: '',
},
methods: {
sendPasswordResetEmail () {
firebase.auth.sendPasswordResetEmail(this.email);
},
},
})
</script>
In addition to the error mentioned in the question, there's another error which shows up, which is [Vue warn]: Error in v-on handler: "TypeError: firebase.auth.sendPasswordResetEmail is not a function". I'm not sure what that means though.
P.S.: I've used Bulma for styling purposes, so the columns and column classes are from there, in case anyone was curious.
Silly me. I forgot a pair of braces in the function I was calling. As André Kool pointed out in the comments, it was supposed to be firebase.auth().sendPasswordResetEmail(this.email);. I missed the parentheses after auth.
Thanks again Mr. André. I ought to up my copy-paste game up one notch.

Popup shows up and then it closes instantly

I'm trying follow the guide from angularfire2 docs on github, but when I try to open the popup window for google login it just closes instantly.
I've tried with different browsers, but I can't figure out what's going on.
Here's the HTML of my form component:
<div class="container " >
<h2 class="date">Wallet manager</h2>
<h1>SUBBO</h1>
<form>
<div class="form-group">
<label class="date" for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label class="date" for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<button type="submit" (click)="login()" style="margin-top:20px" class="btn btn-outline-warning">Login</button>
<button type="submit" (click)="logout()" style="margin-top:20px" class="btn btn-outline-warning">Logout</button>
</form>
</div>
and here is the code:
import { Component, OnInit } from '#angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
#Component({
selector: 'app-login-form',
templateUrl: './login-form.component.html',
styleUrls: ['./login-form.component.css']
})
export class LoginFormComponent implements OnInit {
constructor(public afAuth: AngularFireAuth) {
}
login() {
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleProvider());
}
logout() {
this.afAuth.auth.signOut();
}
ngOnInit() {
}
}
With the login button I call Login() and I was expecting the window to popup and stay there, but it close immediately.
I've uploaded the project to Firebase and it give's me the same problem:
https://subbo-wallet-manager.firebaseapp.com/
I had this same problem using Firebase Authentication. The solution for me was to go into the Firebase Control Panel, select my project, select authentication and under "Sign-in method" I had to add my domain to the authorized domain list. Once I did that, and reloaded the page, it worked.
The fire base documentation gives me this example:
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
Your problem might be the missing then() (it might make it async, not sure). If my guess is wrong, you may still use the catch part to see if any errors occured. Maybe the provider is not valid.
I had the same issue but in my case the login just was failing for Google Chrome, so I tried to update Google Chrome version to the latest one and the login started to work fine again.

Exception from Tracker afterFlush function: TypeError: $(...).calendar is not a function

I am trying to use this npm package ( https://www.npmjs.com/package/semantic-ui-calendar ) with Meteor, but getting this error in the browser console:
Exception from Tracker afterFlush function: TypeError: $(...).calendar
is not a function
I tried following installation to fix this error:
npm i semantic-ui-calendar
npm semantic-ui-calendar --save
meteor npm i semantic-ui-calendar
meteor npm semantic-ui-calendar --save
My code:
blaze-html-template:
<template name="myTemplate">
<h3>Date only</h3>
<div class="ui calendar" id="example2">
<div class="ui input left icon">
<i class="calendar icon"></i>
<input type="text" placeholder="Date">
</div>
</div>
<br/>
</template>
js-template-file:
Template.myTemplate.onRendered(function() {
$(document).ready(function() {
$('#example2').calendar({
type: 'date'
});
});
});
Also moved this JQuery code from onRendered to helpers - without success.
Did you try
npm install --save semantic-ui-calendar
And then import the files from the package by putting the following at the top of your file.
import { ... } from 'semantic-ui-calendar'

Resources