Update master with new auth (#1236)

* Begin UI for threads and moderation overhaul

* Hide close button on non-report threads

* Fix review age coloring

* Add project count

* Remove action buttons from queue page and add queued date to project page

* Hook up to actual data

* Remove unused icon

* Get up to 1000 projects in queue

* prettier

* more prettier

* Changed all the things

* lint

* rebuild

* Add omorphia

* Workaround formatjs bug in ThreadSummary.vue

* Fix notifications page on prod

* Fix a few notifications and threads bugs

* lockfile

* Fix duplicate button styles

* more fixes and polishing

* More fixes

* Remove legacy pages

* More bugfixes

* Add some error catching for reports and notifications

* More error handling

* fix lint

* Add inbox links

* Remove loading component and rename member header

* Rely on threads always existing

* Handle if project update notifs are not grouped

* oops

* Fix chips on notifications page

* Import ModalModeration

* finish threads

* New authentication (#1234)

* Initial new auth work

* more auth pages

* Finish most

* more

* fix on landing page

* Finish everything but PATs + Sessions

* fix threads merge bugs

* fix cf pages ssr

* fix most issues

* Finish authentication

* Fix merge

---------

Co-authored-by: triphora <emma@modrinth.com>
Co-authored-by: Jai A <jaiagr+gpg@pm.me>
Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Prospector
2023-07-20 11:19:42 -07:00
committed by GitHub
parent a5613ebb10
commit 34d63f3557
72 changed files with 2373 additions and 711 deletions

View File

@@ -0,0 +1,113 @@
<template>
<div class="auth-page-container">
<h1>Reset your password</h1>
<template v-if="step === 'choose_method'">
<p>
Enter your email below and we'll send a recovery link to allow you to recover your account.
<NuxtTurnstile ref="turnstile" v-model="token" class="turnstile" />
</p>
<label for="email" hidden>Email or username</label>
<input id="email" v-model="email" type="text" placeholder="Email or username" />
<button class="btn btn-primary continue-btn" @click="recovery">Send recovery email</button>
</template>
<template v-else-if="step === 'passed_challenge'">
<p>Enter your new password below to gain access to your account.</p>
<label for="password" hidden>Password</label>
<input id="password" v-model="newPassword" type="password" placeholder="Password" />
<label for="confirm-password" hi2dden>Password</label>
<input
id="confirm-password"
v-model="confirmNewPassword"
type="password"
placeholder="Confirm password"
/>
<button class="btn btn-primary continue-btn" @click="changePassword">Reset password</button>
</template>
</div>
</template>
<script setup>
useHead({
title: 'Reset Password - Modrinth',
})
const auth = await useAuth()
if (auth.value.user) {
await navigateTo('/dashboard')
}
const data = useNuxtApp()
const route = useRoute()
const step = ref('choose_method')
if (route.query.flow) {
step.value = 'passed_challenge'
}
const turnstile = ref()
const email = ref('')
const token = ref('')
async function recovery() {
startLoading()
try {
await useBaseFetch('auth/password/reset', {
method: 'POST',
body: {
username: email.value,
challenge: token.value,
},
})
data.$notify({
group: 'main',
title: 'Email sent',
text: 'An email with instructions has been sent to you if the email was previously saved on your account.',
type: 'success',
})
} catch (err) {
data.$notify({
group: 'main',
title: 'An error occurred',
text: err.data ? err.data.description : err,
type: 'error',
})
turnstile.value?.reset()
}
stopLoading()
}
const newPassword = ref('')
const confirmNewPassword = ref('')
async function changePassword() {
startLoading()
try {
await useBaseFetch('auth/password', {
method: 'PATCH',
body: {
new_password: newPassword.value,
flow: route.query.flow,
},
})
data.$notify({
group: 'main',
title: 'Password successfully reset',
text: 'You can now log-in into your account with your new password.',
type: 'success',
})
await navigateTo('/auth/sign-in')
} catch (err) {
data.$notify({
group: 'main',
title: 'An error occurred',
text: err.data ? err.data.description : err,
type: 'error',
})
turnstile.value?.reset()
}
stopLoading()
}
</script>

195
pages/auth/sign-in.vue Normal file
View File

@@ -0,0 +1,195 @@
<template>
<div class="auth-page-container">
<template v-if="flow">
<label for="two-factor-code">
<span class="label__title">Enter two-factor code</span>
<span class="label__description">Please enter a two-factor code to proceed.</span>
</label>
<input
id="two-factor-code"
v-model="twoFactorCode"
maxlength="11"
type="text"
placeholder="Enter code..."
/>
<button class="btn btn-primary continue-btn" @click="loginTwoFactor">
Sign in <RightArrowIcon />
</button>
</template>
<template v-else>
<h1>Continue with</h1>
<div class="third-party">
<a class="btn discord-btn" :href="getAuthUrl('discord')">
<DiscordIcon /> <span>Discord</span>
</a>
<a class="btn github-btn" :href="getAuthUrl('github')"
><GitHubIcon /> <span>GitHub</span></a
>
<a class="btn microsoft-btn" :href="getAuthUrl('microsoft')">
<MicrosoftIcon /> <span>Microsoft</span>
</a>
<a class="btn google-btn" :href="getAuthUrl('google')">
<GoogleIcon /> <span>Google</span>
</a>
<a class="btn apple-btn" :href="getAuthUrl('steam')"><SteamIcon /> <span>Steam</span></a>
<a class="btn gitlab-btn" :href="getAuthUrl('gitlab')">
<GitLabIcon /> <span>GitLab</span></a
>
</div>
<div class="text-divider">
<div></div>
<span>or</span>
<div></div>
</div>
<label for="email" hidden>Email or username</label>
<input id="email" v-model="email" type="text" placeholder="Email or username" />
<label for="password" hidden>Password</label>
<input id="password" v-model="password" type="password" placeholder="Password" />
<div class="account-options">
<NuxtTurnstile ref="turnstile" v-model="token" class="turnstile" />
<nuxt-link class="text-link" to="/auth/reset-password">Forgot password?</nuxt-link>
</div>
<button class="btn btn-primary continue-btn" @click="loginPassword()">
Continue <RightArrowIcon />
</button>
<p>
Don't have an account yet?
<nuxt-link
class="text-link"
:to="`/auth/sign-up${route.query.redirect ? `?redirect=${route.query.redirect}` : ''}`"
>
Create one.
</nuxt-link>
</p>
</template>
</div>
</template>
<script setup>
import { GitHubIcon, RightArrowIcon } from 'omorphia'
import DiscordIcon from 'assets/images/utils/discord.svg'
import GoogleIcon from 'assets/images/utils/google.svg'
import SteamIcon from 'assets/images/utils/steam.svg'
import MicrosoftIcon from 'assets/images/utils/microsoft.svg'
import GitLabIcon from 'assets/images/utils/gitlab.svg'
useHead({
title: 'Sign In - Modrinth',
})
const auth = await useAuth()
const route = useRoute()
if (route.fullPath.includes('new_account=true')) {
await navigateTo(
`/auth/welcome?authToken=${route.query.code}${
route.query.redirect ? `&redirect=${encodeURIComponent(route.query.redirect)}` : ''
}`
)
} else if (route.query.code) {
await loginHandler()
}
if (auth.value.user) {
await navigateTo('/dashboard')
}
const data = useNuxtApp()
const turnstile = ref()
const email = ref('')
const password = ref('')
const token = ref('')
const flow = ref(route.query.flow)
async function loginPassword() {
startLoading()
try {
const res = await useBaseFetch('auth/login', {
method: 'POST',
body: {
username: email.value,
password: password.value,
challenge: token.value,
},
})
if (res.flow) {
flow.value = res.flow
} else {
await loginHandler(res.session)
}
} catch (err) {
data.$notify({
group: 'main',
title: 'An error occurred',
text: err.data ? err.data.description : err,
type: 'error',
})
turnstile.value?.reset()
}
stopLoading()
}
const twoFactorCode = ref(null)
async function loginTwoFactor() {
startLoading()
try {
const res = await useBaseFetch('auth/login/2fa', {
method: 'POST',
body: {
flow: flow.value,
code: twoFactorCode.value ? twoFactorCode.value.toString() : twoFactorCode.value,
},
})
await loginHandler(res.session)
} catch (err) {
data.$notify({
group: 'main',
title: 'An error occurred',
text: err.data ? err.data.description : err,
type: 'error',
})
turnstile.value?.reset()
}
stopLoading()
}
async function loginHandler(token) {
if (token) {
await useAuth(token)
await useUser()
}
if (route.query.redirect) {
await navigateTo(route.query.redirect)
} else {
await navigateTo('/dashboard')
}
}
</script>
<style lang="scss" scoped>
.totp {
justify-content: center;
}
.totp-codes {
justify-content: center;
display: grid;
gap: var(--gap-md);
grid-template-columns: repeat(2, 1fr);
width: 100%;
}
.account-options {
display: flex;
width: 100%;
margin-block-start: 0 !important;
}
.account-options a {
margin-left: auto;
}
</style>

144
pages/auth/sign-up.vue Normal file
View File

@@ -0,0 +1,144 @@
<template>
<div class="auth-page-container">
<h1>Create your account</h1>
<div class="third-party">
<a class="btn discord-btn" :href="getAuthUrl('discord')">
<DiscordIcon /> <span>Discord</span>
</a>
<a class="btn github-btn" :href="getAuthUrl('github')"><GitHubIcon /> <span>GitHub</span></a>
<a class="btn microsoft-btn" :href="getAuthUrl('microsoft')">
<MicrosoftIcon /> <span>Microsoft</span>
</a>
<a class="btn google-btn" :href="getAuthUrl('google')">
<GoogleIcon /> <span>Google</span>
</a>
<a class="btn apple-btn" :href="getAuthUrl('steam')"><SteamIcon /> <span>Steam</span></a>
<a class="btn gitlab-btn" :href="getAuthUrl('gitlab')"> <GitLabIcon /> <span>GitLab</span></a>
</div>
<div class="text-divider">
<div></div>
<span>or</span>
<div></div>
</div>
<label for="email" hidden>Email</label>
<input id="email" v-model="email" type="text" placeholder="Email" />
<label for="username" hidden>Username</label>
<input id="username" v-model="username" type="text" placeholder="Username" />
<label for="password" hidden>Password</label>
<input id="password" v-model="password" type="password" placeholder="Password" />
<label for="confirm-password" hidden>Password</label>
<input
id="confirm-password"
v-model="confirmPassword"
type="password"
placeholder="Confirm password"
/>
<Checkbox v-model="subscribe" class="subscribe-btn" label="Subscribe updates about Modrinth" />
<p>
By creating an account, you agree to Modrinth's
<nuxt-link to="/legal/terms" class="text-link">terms</nuxt-link> and
<nuxt-link to="/legal/privacy" class="text-link">privacy policy</nuxt-link>.
</p>
<button class="btn btn-primary continue-btn" @click="createAccount">
Create account <RightArrowIcon />
</button>
<p>
Already have an account yet?
<nuxt-link
class="text-link"
:to="`/auth/sign-in${route.query.redirect ? `?redirect=${route.query.redirect}` : ''}`"
>
Sign in.
</nuxt-link>
<NuxtTurnstile ref="turnstile" v-model="token" class="turnstile" />
</p>
</div>
</template>
<script setup>
import { GitHubIcon, RightArrowIcon, Checkbox } from 'omorphia'
import DiscordIcon from 'assets/images/utils/discord.svg'
import GoogleIcon from 'assets/images/utils/google.svg'
import SteamIcon from 'assets/images/utils/steam.svg'
import MicrosoftIcon from 'assets/images/utils/microsoft.svg'
import GitLabIcon from 'assets/images/utils/gitlab.svg'
useHead({
title: 'Sign Up - Modrinth',
})
const auth = await useAuth()
const route = useRoute()
if (route.fullPath.includes('new_account=true')) {
await navigateTo(
`/auth/welcome?authToken=${route.query.code}${
route.query.redirect ? `&redirect=${encodeURIComponent(route.query.redirect)}` : ''
}`
)
}
if (auth.value.user) {
await navigateTo('/dashboard')
}
const data = useNuxtApp()
const turnstile = ref()
const email = ref('')
const username = ref('')
const password = ref('')
const confirmPassword = ref('')
const token = ref('')
const subscribe = ref(true)
async function createAccount() {
startLoading()
try {
if (confirmPassword.value !== password.value) {
data.$notify({
group: 'main',
title: 'An error occurred',
text: 'Passwords do not match!',
type: 'error',
})
turnstile.value?.reset()
}
const res = await useBaseFetch('auth/create', {
method: 'POST',
body: {
username: username.value,
password: password.value,
email: email.value,
challenge: token.value,
sign_up_newsletter: subscribe.value,
},
})
await useAuth(res.session)
await useUser()
if (route.query.redirect) {
await navigateTo(route.query.redirect)
} else {
await navigateTo('/dashboard')
}
} catch (err) {
data.$notify({
group: 'main',
title: 'An error occurred',
text: err.data ? err.data.description : err,
type: 'error',
})
turnstile.value?.reset()
}
stopLoading()
}
</script>
<style lang="scss" scoped>
.subscribe-btn {
margin-block-start: 0 !important;
}
</style>

View File

@@ -0,0 +1,78 @@
<template>
<div class="auth-page-container">
<template v-if="auth.user && auth.user.email_verified && !success">
<h1>Email already verified</h1>
<p>Your email is already verified!</p>
<nuxt-link class="btn" link="/settings/account">
<SettingsIcon /> Account settings
</nuxt-link>
</template>
<template v-else-if="success">
<h1>Email verification</h1>
<p>Your email address has been successfully verified!</p>
<nuxt-link v-if="auth.user" class="btn" to="/settings/account">
<SettingsIcon /> Account settings
</nuxt-link>
<nuxt-link v-else to="/auth/sign-in" class="btn btn-primary continue-btn">
Sign in <RightArrowIcon />
</nuxt-link>
</template>
<template v-else>
<h1>Email verification failed</h1>
<p>
We were unable to verify your email.
<template v-if="auth.user">
Try re-sending the verification email through the button below.
</template>
<template v-else>
Try re-sending the verification email through your dashboard by signing in.
</template>
</p>
<button v-if="auth.user" class="btn btn-primary continue-btn" @click="resendVerifyEmail">
Resend verification email <RightArrowIcon />
</button>
<nuxt-link v-else to="/auth/sign-in" class="btn btn-primary continue-btn">
Sign in <RightArrowIcon />
</nuxt-link>
</template>
</div>
</template>
<script setup>
import { SettingsIcon, RightArrowIcon } from 'omorphia'
useHead({
title: 'Verify Email - Modrinth',
})
const auth = await useAuth()
const success = ref(false)
const route = useRoute()
if (route.query.flow) {
try {
const emailVerified = useState('emailVerified', () => null)
if (emailVerified.value === null) {
await useBaseFetch('auth/email/verify', {
method: 'POST',
body: {
flow: route.query.flow,
},
})
emailVerified.value = true
success.value = true
}
if (emailVerified.value) {
success.value = true
if (auth.value.token) {
await useAuth(auth.value.token)
}
}
} catch (err) {
success.value = false
}
}
</script>

46
pages/auth/welcome.vue Normal file
View File

@@ -0,0 +1,46 @@
<template>
<div class="auth-page-container">
<h1>Welcome to Modrinth!</h1>
<p>
Thank you for creating an account. You can now follow and create projects, receive updates
about your favorite projects, and more!
</p>
<Checkbox v-model="subscribe" class="subscribe-btn" label="Subscribe updates about Modrinth" />
<button class="btn btn-primary continue-btn" @click="continueSignUp">Continue</button>
<p>
By creating an account, you agree to Modrinth's
<nuxt-link to="/legal/terms" class="text-link">terms</nuxt-link> and
<nuxt-link to="/legal/privacy" class="text-link">privacy policy</nuxt-link>.
</p>
</div>
</template>
<script setup>
import { Checkbox } from 'omorphia'
useHead({
title: 'Welcome - Modrinth',
})
const subscribe = ref(true)
async function continueSignUp() {
const route = useRoute()
await useAuth(route.query.authToken)
await useUser()
if (subscribe.value) {
try {
await useBaseFetch('auth/email/subscribe', {
method: 'POST',
})
} catch {}
}
if (route.query.redirect) {
await navigateTo(route.query.redirect)
} else {
await navigateTo('/dashboard')
}
}
</script>