EDIT #2
So I now have the following https://gist.github.com/benbagley/ef13bc70c62f2cc367561e3927a368fd
The error I am getting is
Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).
I am only initialising firebase in the firebase.js file nowhere else.
EDIT
Here's a GIF on what's happening:
https://i.gyazo.com/0446e6b492aae300870a32f8bb2b2aa8.mp4
Hi I'm using Nuxt to build a test app however I am getting the following error
[Vue warn]: Error in created hook: "ReferenceError: firebase is not defined"
In Nuxt I have an app.html file with firebase being linked in the rest of the app like so
index.vue
<template>
<section class="flex h-screen w-screen uppercase shadow leading-loose">
<section id="large-header" class="relative w-full overflow-hidden bg-cover bg-center gradient-background">
<canvas id="demo-canvas"></canvas>
<section class="flex flex-wrap w-full max-w-xs absolute m-0 bg-white shadow content">
<section v-if="authUser" class="bg-white p-8">
<h2 class="text-3xl text-black">Signed in as {{ authUser.email }}</h2>
<button #click='signOut' class="twitch flex justify-center items-center p-8 uppercase text-white font-semibold tracking-wide w-full">
Sign Out
</button>
</section>
<section class="pt-4 pl-4 pb-0 pr-4" v-else>
<tabs class="flex flex-wrap border-b w-full pt-2">
<tab name="Sign In">
<SignIn style="outline:none" />
</tab>
<tab name="Sign Up">
<SignUp style="outline:none" />
</tab>
</tabs>
</section>
<button class="twitch flex justify-center items-center p-8 uppercase text-white font-semibold tracking-wide w-full">
<i class="fab fa-twitch pr-2 text-xl"></i> Twitch
</button>
</section>
</section>
</section>
</template>
<script>
import SignIn from '#/components/Forms/SignIn'
import SignUp from '#/components/Forms/SignUp'
import {Tabs, Tab} from 'vue-tabs-component';
export default {
components: {
SignIn,
SignUp,
Tabs,
Tab
},
data: function () {
return {
authUser: null
}
},
methods: {
signOut () {
firebase.auth().signOut()
}
},
created () {
firebase.auth().onAuthStateChanged(user => { this.authUser = user })
}
}
</script>
The line that is causing the issue is this
firebase.auth().onAuthStateChanged(user => { this.authUser = user })
Sign up work and so does sign in however when I add the above line the entire app just crashes producing the following error
[Vue warn]: Error in created hook: "ReferenceError: firebase is not defined"
Any help is appreciated!
Typically, you would install the Firebase SDK via
npm install --save firebase
(or yarn if that's your thing)
Then you import it where required like any other module.
I recommend creating a module for your firebase app that can be imported elsewhere, for example, say in src/firebase.js
import firebase from 'firebase' // import the sdk
// initialise your app
export default firebase.initializeApp({
apiKey: "REDACTED",
authDomain: "dashboard-nuxt-test.firebaseapp.com",
databaseURL: "https://dashboard-nuxt-test.firebaseio.com",
projectId: "dashboard-nuxt-test",
storageBucket: "dashboard-nuxt-test.appspot.com",
messagingSenderId: "1234567890"
})
then in your components
import firebase from '#/firebase'
// and later
firebaseApp.auth().onAuthStateChanged(user => { this.authUser = user })
Related
I'm trying to connect my app with facebook login. currently i'm using the developer environment under meta developers account.
I have a login component which looks like below -
import Image from "next/image"
import { signIn } from "next-auth/react"
function Login() {
return (
<div className="grid place-items-center">
<Image
src="https://upload.wikimedia.org/wikipedia/commons/4/44/Facebook_Logo.png?20170210095314"
width={300}
height={300}
style={{objectFit:"contain"}}
alt="logo"
/>
<h1
className="p-5 m-5 bg-blue-500 rounded-full text-white text-center cursor-pointer"
onClick={signIn}>Login with Facebook</h1>
</div>
)
}
export default Login
and here is my code from [...nextauth.js]
import NextAuth from "next-auth"
import FacebookProvider from "next-auth/providers/facebook";
export const authOptions = {
providers: [
FacebookProvider({
clientId: process.env.FACEBOOK_CLIENT_ID,
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
}),
],
}
export default NextAuth(authOptions)
When i click on login with facebook button it throws error
Any help .....
If anyone encountered the same problem below solution works for me.
I made a silly mistake. The Problem was with NEXT_AUTH_URL.
The url was pointing to https://localhost:3000 which is creating the issue.
I have updated url to http://localhost:3000.
And everything working fine.
I am creating a directory of users in Next.js. The users are stored in Supabase. I need for all the users to be displayed in the index.js file, looping through them and showing them on a grid. This is working with getStaticProps, fetching the data and passing it as props profiles.
However, when clicking on each profile, it does redirect me to the [id].js page, but it appends /undefined to the url, rather than the id.
My file tree looks as follows:
pages
people
index.js
[id].js
export default function People({ profiles }) {
return (
<div className="body min-h-[90vh]">
<Head>
<title>People</title>
<link rel="icon" href="/logo" />
</Head>
<div
key={profiles.id}
profiles={profiles}
className="flex flex-col items-center py-16"
>
<div className="grid md:grid-flow-col md:grid-cols-3 xl:grid-cols-4 gap-8 lg:gap-12">
{profiles.map((profile) => (
<Link href={`/people/${profiles.id}`} key={profiles.id}>
<div
profile={profile}
id={profile.id}
className="flex flex-col w-full justify-center items-center p-8 shadow-md hover:shadow-lg"
>
{profile.avatar_url && (
<Image
src={profile.avatar_url}
alt="profile picture"
width={200}
height={200}
className="rounded-full"
object-fit="cover"
/>
)}
<h1 className="text-2xl pt-8 text-center">
{profile.full_name}
</h1>
<p>{profile.skills.skill}</p>
<button className="button w-full">See lessons</button>
</div>
</Link>
))}
</div>
</div>
</div>
);
}
export async function getStaticProps() {
const supabaseAdmin = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL || "",
process.env.SUPABASE_SERVICE_ROLE_KEY || ""
);
const { data } = await supabaseAdmin
.from("profiles")
.select("*, skills(skill)")
.order("id");
console.log(data);
return {
props: {
profiles: data,
},
};
}
Any ideas as to what I am doing wrong are highly appreciated.
Thanks.
I am trying to create a Vue component which wraps a Popoverfrom headlessui
I am trying to toggle open close using the slot binding as suggested in the popover docs. I cannot get this to work. Nothing appears in the UI, even if I had it working ok from within the element itself, granted that is neither a good place to put it because the elements render as many rows there are in the table.
Does anyone have any wisdom surrounding headless UI popovers in Vue3 on a table row?
EDIT:
Ok adding static to the PopoverPanelmakes it render when open=true
, the issue now being that multiple instances render based on the number of elements in the table. So this is a new issue.
<template>
<div>
<Popover :slot="{pop}">
<transition
enter-active-class="transition duration-200 ease-out"
enter-from-class="translate-y-1 opacity-0"
enter-to-class="translate-y-0 opacity-100"
leave-active-class="transition duration-150 ease-in"
leave-from-class="translate-y-0 opacity-100"
leave-to-class="translate-y-1 opacity-0"
>
<PopoverPanel static class="absolute z-9 mt-3 max-w-sm -translate-x-1/2 transform sm:px-0 lg:max-w-3xl">
<div class="rounded-lg shadow-lg w-full m-2">
<div
v-if="pop"
ref="popover"
class="flex flex-col p-2"
>
<ButtonTemp label="Send reminder" btn-type="m-0.5 bg-neutral-200 text-neutral-900 text-left text-caption hover:bg-neutral-900 hover:text-neutral-100" icon-left>
<IconsMail />
</ButtonTemp>
<ButtonTemp label="Share candidate" btn-type="m-0.5 bg-neutral-200 text-neutral-900 text-caption hover:bg-neutral-900 hover:text-neutral-100" icon-left>
<IconsExternalLink />
</ButtonTemp>
<ButtonTemp label="Remove from assignment" btn-type="m-0.5 bg-neutral-200 text-neutral-900 text-caption hover:bg-danger-100 hover:text-neutral-100" icon-left>
<IconsUserMinus />
</ButtonTemp>
</div>
</div>
</PopoverPanel>
</transition>
</Popover>
<script setup lang="ts">
import { Ref } from '#vue/runtime-core';
import { Popover, PopoverButton, PopoverPanel } from '#headlessui/vue';
import { ButtonTemp, IconsMail, IconsExternalLink, IconsUserMinus } from '#/.nuxt/components';
const pop: Ref<boolean> = ref(true);
interface IContextMenu {
open: boolean;
}
const props = defineProps<IContextMenu>();
const isOpen = toRef(props, 'open');
watch(isOpen, (is) => {
if (is) {
console.log('open', is);
pop.value = !pop.value;
}
});
onMounted(() => {
pop.value = true;
});
</script>
Component where it is to be used:
......
<td class="group-hover:text-neutral-100 rounded-r">
<button
class="m-auto h-8 w-8 rounded-sm flex justify-center items-center group-hover:bg-neutral-700 cursor-pointer"
#click="handleClick(candidate.id, '')"
>
<ContextMenu :open="open" /> // Popover wrapped component
<IconsVerticalMenu />
</button>
</td>
</tr>
Problem
I'm doing some development using Next.js and ZKSwap API, but I can't figure out how to use the ABI of the deployed smart contract.
Specifically, I want to call this DepositETH.
https://en.wiki.zks.org/interact-with-zkswap/make-transaction#deposit-eth
And it seems that I need to configure this ABI to call it, but I don't know how to configure it.
https://en.wiki.zks.org/interact-with-zkswap/make-transaction#abis
What I Did
I implemented it as follows, but it didn't work.
import { Wallet, Contract, utils } from 'ethers'
import Web3 from 'web3'
import zkswapABI from '../src/zkswap.ABI.json'
const Web3EthAbi = require('web3-eth-abi');
export default function zkswap() {
//try2
let ABI = zkswapABI
const wallet = new Wallet('0x1c1a49fea9a4ede1dc8e582639f498d41fa3c4a9e2ab2b9d740a4a3ec14e1cbf')
const contract = new Contract('0x8ECa806Aecc86CE90Da803b080Ca4E3A9b8097ad', ABI, wallet)
async function depositETH(amount) {
const tx = await contract.depositETH(wallet.address, {
value: utils.parse(amount)
})
return tx
}
depositETH('0.5').then(console.log)
return (
<div>
<section className="h-screen w-4/5 max-w-5xl mx-auto flex items-center justify-center flex-col">
<h1 className="mb-4 text-green-500 text-3xl">sample</h1>
<p className="mb-2 text-center"> ZKSwap </p>
<button className="btn-blue" onClick={depositETH}> Deposit ETH</button>
</section>
</div>
)
}
Error
In fact, when I tried to 'yarn dev', I got an error like this
TypeError: ethers__WEBPACK_IMPORTED_MODULE_1__.utils.parse is not a function
I'm building a personal website with Nextjs and I'm encountering a weird issue with the Public folder. Per the documentation, static images are to be put in the Public folder. This works perfectly for all images in my local development mode. However, as soon as I push this to production with Vercel, some images would fail to render (showing broken image). I noticed it seems to load jpg images fine but not png / svg. I don't use next-images module and just use a simple tag.
My file structure (simplified) is:
public
static
Melbourne.jpg
avatar.png
pages
index.jsx
In my index.jsx (also super simplied)
function Homepage({ data }) {
return (
<motion.div id='home' initial='initial' animate='enter' exit='exit'>
<section
id='intro'
className='bg-dark flex content-center flex-wrap p-40 justify-center text-center min-h-screen w-screen'>
<div className='flex flex-col justify-center'>
<motion.img
src='/static/avatar.png' <-- Works in Dev but not Prod
className='flex mx-auto rounded-full h-32 w-32'
variants={{
initial: { opacity: 0 },
enter: {
opacity: 1,
transition: {
ease: 'easeIn',
duration: 0.5,
delay: 0.75,
},
},
}}
/>
</div>
</section>
<section id='about' className='bg-light w-screen p-10'>
<div className='h-2 border-t-4 border-dark w-10/12 flex flex-column mx-auto mt-12' />
<div className='w-1/3 mx-auto relative bottom-12 bg-light'>
<h1 className='font-header text-center'>About Me</h1>
</div>
<div className='flex mx-auto mb-8 w-11/12 md:w-3/4 grid grid-cols-3 gap-6 lg:grid-cols-3'>
<div className='py-8 col-span-2'>
Some text here
</div>
<div className=''>
<img
className='rounded-full w-full h-full'
src='/static/Melbourne.jpg' <-- Works in Dev & Prod
alt='melbourne-skyline'
/>
</div>
</div>
</section>
</motion.div>
);
}
export default Homepage;
Please ignore any possible syntax error, everything works on my end and I deleted a lot of things to simplify this. The only issue I'm encountering is the tag.
Thanks in advance for your help!
You have to rebuild [ npm run build ] the project after adding new assets, then commit the changes.