Skip to content

Commit

Permalink
Remove @libsql/client dependency (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowonpaper authored Jul 17, 2023
1 parent 39b6b8f commit e539e77
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .auri/$gehg0gxs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
package: "@lucia-auth/adapter-sqlite" # package name
type: "patch" # "major", "minor", "patch"
---

Remove `@libsql/client` import
4 changes: 3 additions & 1 deletion packages/adapter-sqlite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"adapter",
"sql",
"kysely",
"drizzle"
"drizzle",
"libsql",
"turso"
],
"repository": {
"type": "git",
Expand Down
33 changes: 15 additions & 18 deletions packages/adapter-sqlite/src/drivers/libsql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
UserSchema,
KeySchema
} from "lucia";
import { Client, LibsqlError } from "@libsql/client";
import type { Client, LibsqlError } from "@libsql/client";

export const libsqlAdapter = (
db: Client,
Expand Down Expand Up @@ -51,10 +51,10 @@ export const libsqlAdapter = (
};
await db.batch("write", [insertUserQuery, insertKeyQuery]);
} catch (e) {
const error = e as Partial<LibsqlError>;
if (
e instanceof LibsqlError &&
e.code === "SQLITE_CONSTRAINT_PRIMARYKEY" &&
e.message?.includes(".id")
error.code === "SQLITE_CONSTRAINT_PRIMARYKEY" &&
error.message?.includes(".id")
) {
throw new LuciaError("AUTH_DUPLICATE_KEY_ID");
}
Expand Down Expand Up @@ -111,10 +111,8 @@ export const libsqlAdapter = (
args
});
} catch (e) {
if (
e instanceof LibsqlError &&
e.code === "SQLITE_CONSTRAINT_FOREIGNKEY"
) {
const error = e as Partial<LibsqlError>;
if (error.code === "SQLITE_CONSTRAINT_FOREIGNKEY") {
throw new LuciaError("AUTH_INVALID_USER_ID");
}
throw e;
Expand Down Expand Up @@ -174,16 +172,15 @@ export const libsqlAdapter = (
args
});
} catch (e) {
if (e instanceof LibsqlError) {
if (e.code === "SQLITE_CONSTRAINT_FOREIGNKEY") {
throw new LuciaError("AUTH_INVALID_USER_ID");
}
if (
e.code === "SQLITE_CONSTRAINT_PRIMARYKEY" &&
e.message?.includes(".id")
) {
throw new LuciaError("AUTH_DUPLICATE_KEY_ID");
}
const error = e as Partial<LibsqlError>;
if (error.code === "SQLITE_CONSTRAINT_FOREIGNKEY") {
throw new LuciaError("AUTH_INVALID_USER_ID");
}
if (
error.code === "SQLITE_CONSTRAINT_PRIMARYKEY" &&
error.message?.includes(".id")
) {
throw new LuciaError("AUTH_DUPLICATE_KEY_ID");
}
throw e;
}
Expand Down

0 comments on commit e539e77

Please sign in to comment.