Skip to content

Commit

Permalink
CI: Release (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucythecat authored Aug 13, 2023
1 parent 10019b4 commit 56478a7
Show file tree
Hide file tree
Showing 20 changed files with 357 additions and 361 deletions.
6 changes: 0 additions & 6 deletions .auri/$ag7ys15z.md

This file was deleted.

6 changes: 0 additions & 6 deletions .auri/$m3rtr8cd.md

This file was deleted.

6 changes: 0 additions & 6 deletions .auri/$nziehqul.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,36 @@ let errorMessage: string | null = null;
const session = await Astro.locals.auth.validate();
if (!session) return Astro.redirect("/login");
if (session.user.emailVerified) {
return Astro.redirect("/");
return Astro.redirect("/");
}
if (Astro.request.method === "POST") {
try {
const token = await generateEmailVerificationToken(session.user.userId);
await sendEmailVerificationLink(token);
success = true;
} catch {
errorMessage = "An unknown error occurred";
Astro.response.status = 500
}
try {
const token = await generateEmailVerificationToken(session.user.userId);
await sendEmailVerificationLink(token);
success = true;
} catch {
errorMessage = "An unknown error occurred";
Astro.response.status = 500;
}
}
---

<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Email & password auth with Lucia</title>
</head>
<body>
<h1>Email verification</h1>
<p>
Your email verification link was sent to your inbox (i.e. console).
</p>
<h2>Resend verification link</h2>
<form method="post">
<input type="submit" value="Resend" />
</form>
{success && <p>Your verification link was resent</p>}
<p class="error">{errorMessage}</p>
</body>
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Email & password auth with Lucia</title>
</head>
<body>
<h1>Email verification</h1>
<p>Your email verification link was sent to your inbox (i.e. console).</p>
<h2>Resend verification link</h2>
<form method="post">
<input type="submit" value="Resend" />
</form>
{success && <p>Your verification link was resent</p>}
<p class="error">{errorMessage}</p>
</body>
</html>
22 changes: 11 additions & 11 deletions examples/astro/email-and-password/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
import "../app.css"
import "../app.css";
const session = await Astro.locals.auth.validate();
if (!session) return Astro.redirect("/login");
if (!session.user.emailVerified) {
return Astro.redirect("/email-verification")
return Astro.redirect("/email-verification");
}
---

<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Email & password auth with Lucia</title>
</head>
<body>
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Email & password auth with Lucia</title>
</head>
<body>
<h1>Profile</h1>
<p>User id: {session.user.userId}</p>
<p>Email: {session.user.email}</p>
<form method="post" action="/logout">
<input type="submit" value="Sign out" />
</form>
</body>
</body>
</html>
6 changes: 3 additions & 3 deletions examples/astro/email-and-password/src/pages/login.astro
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ if (Astro.request.method === "POST") {
// user does not exist
// or invalid password
errorMessage = "Incorrect email or password";
Astro.response.status = 400
Astro.response.status = 400;
} else {
errorMessage = "An unknown error occurred";
Astro.response.status = 500
Astro.response.status = 500;
}
}
} else {
errorMessage = "Invalid input";
Astro.response.status = 400
Astro.response.status = 400;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,62 @@ import { validatePasswordResetToken } from "../../lib/token";
let errorMessage = "";
if (Astro.request.method === "POST") {
const formData = await Astro.request.formData();
const password = formData.get("password");
// basic check
const validPassword =
typeof password === "string" &&
password.length >= 6 &&
password.length <= 255;
if (validPassword) {
try {
const { token } = Astro.params;
if (!token) {
return new Response(null, {
status: 404
});
}
const userId = await validatePasswordResetToken(token);
let user = await auth.getUser(userId);
await auth.invalidateAllUserSessions(user.userId);
await auth.updateKeyPassword("email", user.email, password);
if (!user.emailVerified) {
user = await auth.updateUserAttributes(user.userId, {
email_verified: Number(true)
});
}
const session = await auth.createSession({
userId: user.userId,
attributes: {}
});
Astro.locals.auth.setSession(session);
return Astro.redirect("/")
} catch (e) {
errorMessage = "Invalid or expired password reset link";
Astro.response.status = 400
}
} else {
errorMessage = "Invalid password";
Astro.response.status = 400
}
const formData = await Astro.request.formData();
const password = formData.get("password");
// basic check
const validPassword =
typeof password === "string" &&
password.length >= 6 &&
password.length <= 255;
if (validPassword) {
try {
const { token } = Astro.params;
if (!token) {
return new Response(null, {
status: 404
});
}
const userId = await validatePasswordResetToken(token);
let user = await auth.getUser(userId);
await auth.invalidateAllUserSessions(user.userId);
await auth.updateKeyPassword("email", user.email, password);
if (!user.emailVerified) {
user = await auth.updateUserAttributes(user.userId, {
email_verified: Number(true)
});
}
const session = await auth.createSession({
userId: user.userId,
attributes: {}
});
Astro.locals.auth.setSession(session);
return Astro.redirect("/");
} catch (e) {
errorMessage = "Invalid or expired password reset link";
Astro.response.status = 400;
}
} else {
errorMessage = "Invalid password";
Astro.response.status = 400;
}
}
---

<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Email & password auth with Lucia</title>
</head>
<body>
<h1>Reset password</h1>
<form method="post">
<label for="password">New Password</label>
<input name="password" id="password" /><br />
<input type="submit" />
</form>
<p class="error">{errorMessage}</p>
</body>
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Email & password auth with Lucia</title>
</head>
<body>
<h1>Reset password</h1>
<form method="post">
<label for="password">New Password</label>
<input name="password" id="password" /><br />
<input type="submit" />
</form>
<p class="error">{errorMessage}</p>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,55 @@ let success = false;
let errorMessage: string | null = null;
if (Astro.request.method === "POST") {
const formData = await Astro.request.formData();
const email = formData.get("email");
if (typeof email === "string") {
emailInput = email;
}
if (isValidEmail(email)) {
try {
const storedUser = await db
.selectFrom("user")
.selectAll()
.where("email", "=", email)
.executeTakeFirst();
if (storedUser) {
const user = auth.transformDatabaseUser(storedUser);
const token = await generatePasswordResetToken(user.userId);
await sendPasswordResetLink(token);
success = true;
} else {
errorMessage = "User does not exist";
Astro.response.status = 400
}
} catch (e) {
errorMessage = "An unknown error occurred";
Astro.response.status = 500
}
} else {
errorMessage = "Invalid email";
Astro.response.status = 400
}
const formData = await Astro.request.formData();
const email = formData.get("email");
if (typeof email === "string") {
emailInput = email;
}
if (isValidEmail(email)) {
try {
const storedUser = await db
.selectFrom("user")
.selectAll()
.where("email", "=", email)
.executeTakeFirst();
if (storedUser) {
const user = auth.transformDatabaseUser(storedUser);
const token = await generatePasswordResetToken(user.userId);
await sendPasswordResetLink(token);
success = true;
} else {
errorMessage = "User does not exist";
Astro.response.status = 400;
}
} catch (e) {
errorMessage = "An unknown error occurred";
Astro.response.status = 500;
}
} else {
errorMessage = "Invalid email";
Astro.response.status = 400;
}
}
---

<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Email & password auth with Lucia</title>
</head>
<body>
<h1>Reset password</h1>
<form method="post">
<label for="email">Email</label>
<input name="email" id="email" value={emailInput} /><br />
<input type="submit" />
</form>
<p class="error">{errorMessage}</p>
{success && <p>Your password reset link was sent to your inbox</p>}
<a href="/login">Sign in</a>
</body>
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Email & password auth with Lucia</title>
</head>
<body>
<h1>Reset password</h1>
<form method="post">
<label for="email">Email</label>
<input name="email" id="email" value={emailInput} /><br />
<input type="submit" />
</form>
<p class="error">{errorMessage}</p>
{success && <p>Your password reset link was sent to your inbox</p>}
<a href="/login">Sign in</a>
</body>
</html>
Loading

1 comment on commit 56478a7

@vercel
Copy link

@vercel vercel bot commented on 56478a7 Aug 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.