Back

[SOLVED] Protect User's Data

  • 0
  • Web
  • Cloud
Susmita
28 May, 2023, 16:11

Solved the above error

TL;DR
The user is experiencing an error regarding invalid permissions in their code. The solution to the issue is to remove the line of code that references the "user" role in the permissions. This should fix the main issue.
Susmita
28 May, 2023, 16:11

But still the main issue persists

Hexi
28 May, 2023, 16:26

Have you edited the original permissions?

Hexi
28 May, 2023, 16:26

so remove this from the collection

Susmita
28 May, 2023, 16:27

wait let me do it

Hexi
28 May, 2023, 16:27

Ah then that is probably the issue

Susmita
28 May, 2023, 16:28

New error:

AppwriteException: Invalid permissions: Role "user" identifier value is invalid: Parameter must contain at most 36 chars. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char

Hexi
28 May, 2023, 16:29

What is your code your having with the imports?

Susmita
28 May, 2023, 16:30

import React, { useState } from 'react' import { v4 as uuidv4 } from 'uuid' import { databases } from '@/appwrite/appwrite' import { Permission, Role } from 'appwrite';

function TodoForm(userId) { const [todoItem, setTodoItem] = useState("") const data = { todoitem: todoItem }; console.log(data);

TypeScript
const handleSubmit = (e) => {
    e.preventDefault()
    const promise = databases.createDocument(
        "DATABASE_ID",
        "COLLECTION_ID",
        uuidv4(),
        data,
        [
            Permission.write(Role.user(userId)), // User can write this document
        ]
    )

    console.log(promise);
    promise.then(
        function (response) {
            console.log(response);
            // window.location.reload()
        },
        function (error) {
            console.log(error);
            // window.location.reload()
        },
    );
    e.target.reset()
}


return (
    <div className="max-w-7xl mx-auto mt-10 text-white">
        <form
            action=""
            onSubmit={handleSubmit}
            className="flex justify-center mb-10"
        >
            <input
                type="text"
                name=""
                id=""
                placeholder="Enter Todo"
                className="border p-2 w-2/3 rounded-md text-black placeholder-gray-600"
                onChange={(e) => {
                    setTodoItem(e.target.value)
                }}
            />
            <button
                className="bg-pink-600 hover:bg-pink-700 p-2 text-white ml-2 rounded-md"
                type="submit"
            >
                Add Todo
            </button>
        </form>
    </div>
)

}

export default TodoForm

Susmita
28 May, 2023, 16:30

This is the code

Susmita
28 May, 2023, 16:30

check once

Hexi
28 May, 2023, 16:31

I think this needs to be update not write

Hexi
28 May, 2023, 16:31

I dont think permission write is a thing

Susmita
28 May, 2023, 16:32

there is

Hexi
28 May, 2023, 16:32

hmmm

Hexi
28 May, 2023, 16:33

Nvm ^_^

Hexi
28 May, 2023, 16:33

maybe log the userId?

Hexi
28 May, 2023, 16:34

see what it returns with

Susmita
28 May, 2023, 16:34

It returns the user id

Hexi
28 May, 2023, 16:35

Because here it says the user is wrong

Susmita
28 May, 2023, 16:36

But I'm just trying to add new todo

Hexi
28 May, 2023, 16:38

I sadly have not a clue why it returns that maybe wait for someone else?

Susmita
28 May, 2023, 16:38

Okay

Susmita
29 May, 2023, 03:30

Solved using <#1112060655072190464>

Susmita
29 May, 2023, 03:30

[SOLVED] Protect User's Data

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