Skip to content

Commit

Permalink
fix: check for verified emails on auth'd paths
Browse files Browse the repository at this point in the history
  • Loading branch information
brettski committed Oct 19, 2023
1 parent 7457360 commit 7c8b291
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thatconference.com",
"version": "5.1.3",
"version": "5.1.4",
"description": "THATConference.com website",
"main": "index.js",
"type": "module",
Expand Down
13 changes: 12 additions & 1 deletion src/hooks.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ async function authorization({ event, resolve }) {
}
throw redirect(303, `/login-redirect?returnTo=${toPath}`);
}

if (!session.user.sub.startsWith('twitter') && session.user?.emailVerified === false) {
throw redirect(307, `/verify-account`);
}
}

return resolve(event);
Expand Down Expand Up @@ -71,14 +75,19 @@ const authConfig = {
if (url.startsWith('/')) return `${baseUrl}${url}`;
// Allows callback URLs on the same origin
else if (new URL(url).origin === baseUrl) return url;

return baseUrl;
},
jwt(jwtGoo) {
const { account, token } = jwtGoo;
const { account, token, profile } = jwtGoo;
if (account) {
token.accessToken = account.access_token;
token.idToken = account.id_token;
}
if (profile) {
token.emailVerified = profile.email_verified;
}

return token;
},
session(sessionGoo) {
Expand All @@ -87,13 +96,15 @@ const authConfig = {
session.idToken = token.idToken;
session.user.id = token.sub;
session.user.sub = token.sub;
session.user.emailVerified = token.emailVerified;
const payload = parseOnly(token.accessToken);
if (payload) {
const { permissions } = payload;
if (permissions && Array.isArray(permissions)) {
session.user.permissions = permissions;
}
}

return session;
}
}
Expand Down

0 comments on commit 7c8b291

Please sign in to comment.