Git Product home page Git Product logo

sveltekit-auth-cookies's People

Contributors

mattcroat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sveltekit-auth-cookies's Issues

Update to Kit 1.0

Now that version 1.0 is stable and released this would be lovely to have with the latest version of Sveltekit.

I know this was requested before in #2, but would be lovely if time is available. Gave it a try without success.

500 Internal Error

Hi,
following your Project Setup on https://github.com/joysofcode/sveltekit-auth-cookies
I get this error when trying to register a new user (test/test1)

image

` โžœ Local: http://localhost:4173/
โžœ Network: use --host to expose
Error:
Invalid prisma.user.create() invocation:

An operation failed because it depends on one or more records that were required but not found. No 'Roles' record(s) (needed to inline the relation on 'User' record(s)) was found for a nested connect on one-to-many relation 'RolesToUser'.
at RequestHandler.handleRequestError (D:\work\nodejs\sveltekit-auth-cookies\node_modules@prisma\client\runtime\index.js:30851:13)
at RequestHandler.request (D:\work\nodejs\sveltekit-auth-cookies\node_modules@prisma\client\runtime\index.js:30834:12)
at async PrismaClient._request (D:\work\nodejs\sveltekit-auth-cookies\node_modules@prisma\client\runtime\index.js:31812:16)
at async register (file:///D:/work/nodejs/sveltekit-auth-cookies/.svelte-kit/output/server/entries/pages/(auth)/register/_page.server.ts.js:22:3)
at async handle_action_json_request (file:///D:/work/nodejs/sveltekit-auth-cookies/.svelte-kit/output/server/index.js:332:18)
at async resolve (file:///D:/work/nodejs/sveltekit-auth-cookies/.svelte-kit/output/server/index.js:1984:22)
at async Object.handle (file:///D:/work/nodejs/sveltekit-auth-cookies/.svelte-kit/output/server/chunks/hooks.server.js:5:12)
at async respond (file:///D:/work/nodejs/sveltekit-auth-cookies/.svelte-kit/output/server/index.js:2022:22)
at async file:///D:/work/nodejs/sveltekit-auth-cookies/node_modules/@sveltejs/kit/src/exports/vite/preview/index.js:145:5
Error:
Invalid prisma.user.create() invocation:`

Please add role management

hi,
could you please add the possibility to assign a registered user a defined role?
eg.:
Admin
User

thx

Invalid request body

Thanks a lot for this example!

After the installation process, i tried to register myself (yes, i added the user-roles) and got an internal server error with the response invalid request body.

After a short research, i found this:
#sveltejs/kit#5370

And updated the sveltejs/kitin the package.json from .504 to the current version .560 and run the installation again.

Now it works

seems simple yet it's not

Is it possible to make an example that connects to supabase instead of prism to set hooks and session. I've tried to adjust but all to no avail

Error: Function called outside component initialization

Steps to reproduce:

  • Cloned the project
  • Completed the steps in the README.md

The server emits this error, when running npm run dev, and no page is loaded:

Function called outside component initialization
Error: Function called outside component initialization
    at get_current_component (/node_modules/svelte/internal/index.mjs:953:15)
    at Module.setContext (/node_modules/svelte/internal/index.mjs:985:5)
    at root.svelte:14:1
    at $$render (/node_modules/svelte/internal/index.mjs?v=39878779:1770:22)
    at Object.render (/node_modules/svelte/internal/index.mjs?v=39878779:1778:26)
    at render_response (file:///Users/john/Code/JoysOfCode/sveltekit-auth-cookies/.svelte-kit/runtime/server/index.js:1283:27)
    at async respond_with_error (file:///Users/john/Code/JoysOfCode/sveltekit-auth-cookies/.svelte-kit/runtime/server/index.js:2663:10)
    at async respond$1 (file:///Users/john/Code/JoysOfCode/sveltekit-auth-cookies/.svelte-kit/runtime/server/index.js:2918:4)
    at async resolve (file:///Users/john/Code/JoysOfCode/sveltekit-auth-cookies/.svelte-kit/runtime/server/index.js:3303:11)
    at async Object.handle (/Users/john/Code/JoysOfCode/sveltekit-auth-cookies/src/hooks.ts:14:11)
    ```
    
    I run on Mac:
    Node version: v18.5.0
    npm version: 8.12.1

Issue: Unable to write to SQLite database

Issue: Unable to write to SQLite database

When trying to register a user in my SvelteKit app with Prisma and SQLite, I receive the following error:

Invalid `prisma.user.create()` invocation:

Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: 
QueryError(SqliteFailure(Error { code: ReadOnly, extended_code: 8 }, 
Some("attempt to write a readonly database"))), transient: false })

I have already tried giving write permissions to both the database and the folder, but the error persists.

Steps to reproduce:

Try to register a new user in the SvelteKit app
Observe the error in the console

Expected behavior:

The user should be successfully registered and added to the SQLite database.

Code

/register/+page.server.ts looks like:

import { fail, redirect } from '@sveltejs/kit'
import bcrypt from 'bcrypt'

import db from '../../../lib/userDatabase';

// using an enum for user roles to avoid typos
// if you're not using TypeScript use an object
enum Roles {
	ADMIN = 'ADMIN',
	USER = 'USER',
}

export const load = async ({ locals }) => {
	// redirect user if logged in
	if (locals.user) {
		throw redirect(302, '/')
	}
}

export const actions = {
	register: async ({ request }) => {
		const data = await request.formData()
		const username = data.get('username')
		const password = data.get('password')
		console.log("request: " + request);

		if (
			typeof username !== 'string' ||
			typeof password !== 'string' ||
			!username ||
			!password
		) {
			return fail(400, { invalid: true })
		}
		const user = await db.user.findUnique({
			where: { username },
		})

		if (user) {
			return fail(400, { user: true })
		}

		await db.user.create({
			data: {
				username,
				passwordHash: await bcrypt.hash(password, 10),
				userAuthToken: crypto.randomUUID(),
				role: { connect: { name: Roles.USER } },
			}, 
		})
		console.log("data: " + data);
		throw redirect(303, '/login')
	},
}

Environment:

OS: EndeavourOS 6.2.9
NodeJS: 19.8.1
SQLite: 3.41.2
Prisma: 4.12.0
Sveltekit: 1.15.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.