Skip to content

Commit

Permalink
fix docs errors (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushbtw authored Jan 10, 2024
1 parent 4dd0e25 commit 51a84b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
7 changes: 3 additions & 4 deletions docs/pages/basics/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ declare module "lucia" {
Lucia: typeof lucia;
DatabaseSessionAttributes: DatabaseSessionAttributes;
}
}

interface DatabaseSessionAttributes {
country: string;
interface DatabaseSessionAttributes {
ip_country: string;
}
}
```

Expand Down
9 changes: 5 additions & 4 deletions docs/pages/guides/email-and-password/password-reset.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The token should be valid for at most few hours.

```ts
import { TimeSpan, createDate } from "oslo";
import { generateId } from "lucia";

async function createPasswordResetToken(userId: string): Promise<string> {
// optionally invalidate all existing tokens
Expand All @@ -40,7 +41,6 @@ When a user requests a password reset email, check if the email is valid and cre

```ts
import { generateId } from "lucia";
import { encodeHex } from "oslo/encoding";

app.post("/reset-password", async () => {
let email: string;
Expand Down Expand Up @@ -71,7 +71,8 @@ Make sure to implement rate limiting based on IP addresses.
Extract the verification token from the URL and validate by checking the expiration date. If the token is valid, invalidate all existing user sessions, update the database, and create a new session.

```ts
import { isWithinExpiration } from "oslo";
import { isWithinExpirationDate } from "oslo";
import { Argon2id } from "oslo/password";

app.post("/reset-password/:token", async () => {
let password = formData.get("password");
Expand All @@ -95,15 +96,15 @@ app.post("/reset-password/:token", async () => {
status: 400
});
}
if (!isWithinExpiration(token.expires_at)) {
if (!isWithinExpirationDate(token.expires_at)) {
await db.table("password_reset_token").where("id", "=", token.id).delete();
return new Response(null, {
status: 400
});
}

await lucia.invalidateUserSessions(user.id);
const hashedPassword = new Argon2id().hash(password);
const hashedPassword = await new Argon2id().hash(password);
await db.table("user").where("id", "=", user.id).update({
hashed_password: hashedPassword
});
Expand Down
4 changes: 3 additions & 1 deletion docs/pages/tutorials/username-and-password/sveltekit.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Create a form action in `routes/signup/+page.server.ts`. First do a very basic i
// routes/signup/+page.server.ts
import { lucia } from "$lib/server/auth";
import { fail, redirect } from "@sveltejs/kit";
import { Argon2id } from "oslo/password";

import type { Actions } from "./$types";

Expand Down Expand Up @@ -166,6 +167,7 @@ Create an API route as `pages/api/signup.ts`. First do a very basic input valida
```ts
import { lucia } from "$lib/server/auth";
import { fail, redirect } from "@sveltejs/kit";
import { Argon2id } from "oslo/password";

import type { Actions } from "./$types";

Expand Down Expand Up @@ -258,7 +260,7 @@ export const actions: Actions = {
}
await auth.invalidateSession(event.locals.session.id);
const sessionCookie = lucia.createBlankSessionCookie();
context.cookies.set(sessionCookie.name, sessionCookie.value, {
event.cookies.set(sessionCookie.name, sessionCookie.value, {
path: ".",
...sessionCookie.attributes
});
Expand Down

0 comments on commit 51a84b3

Please sign in to comment.