Skip to content
Init is here / May 19 - 23
Back

CORS Error with AppWrite in Framer Code Components

  • 0
  • Auth
  • Web
MemeyMello
1 Nov, 2024, 19:35

I was using Appwrite trying to create a login component in Framer but I am getting an error when I use the createEmailPasswordSession method. The same code works on my Next JS application on localhost but when I try calling this method from the framer component it gives me this error:

Here's my code: import { useState } from "react" import { Client, Account } from "appwrite"

/**

export default function Auth(props) { const [email, setEmail] = useState("&#x6b;&#114;&#x75;&#x74;&#x69;&#107;&#x40;&#x66;&#x72;&#97;&#109;&#x65;&#114;&#46;&#99;&#111;&#109;") const [password, setPassword] = useState("<PASSWORD>")

TypeScript
const client = new Client().setProject("66be39a70024858da9ff")
const account = new Account(client)

async function handleSubmit() {
    if (email === "" || password === "") {
        return
    }
    try {
        const result = await account.createEmailPasswordSession(
            email,
            password
        )

        console.log(`success: `, result)
    } catch (e) {
        console.log(`fail: `, e)
    }
}

return (
    <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
        <input
            style={inputStyle}
            type="email"
            placeholder="krutik@framer.com"
            value={email}
            onChange={(e) => setEmail(e.target.value)}
        />
        <input
            style={inputStyle}
            type="password"
            placeholder="password"
            value={password}
            onChange={(e) => setPassword(e.target.value)}
        />
        <button onClick={handleSubmit} style={buttonStyle}>
            Login
        </button>
    </div>
)

}

TL;DR
Developers experiencing CORS error when trying to create a login component with Appwrite in Framer. Code works on Next JS locally but not in Framer. Solution: Add CORS configuration on the server to allow requests from Framer app domain.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more