Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for verified emails on auth'd paths #116

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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