SignIn only for existing users

This commit is contained in:
2026-06-25 00:59:05 -07:00
parent 6d58559fa9
commit 172e07060a
4 changed files with 40 additions and 13 deletions
@@ -38,7 +38,8 @@ export async function authorizationMiddleware(
try {
const token = req.headers.authorization || ""
const user = await Users.EnsureFromAuth0TokenService.perform(token)
const user = await Users.FindFromAuth0TokenService.perform(token)
//const user = await Users.EnsureFromAuth0TokenService.perform(token)
req.currentUser = user
return next()
} catch (error) {
@@ -0,0 +1,35 @@
import { auth0Integration } from "@/integrations"
import { User } from "@/models"
import { Op } from "@sequelize/core"
import BaseService from "@/services/base-service"
export class FindFromAuth0TokenService extends BaseService {
constructor(private token: string) {
super()
}
async perform(): Promise<User> {
const { auth0Subject, email } = await auth0Integration.getUserInfo(this.token)
const existingUser = await User.withScope(["asCurrentUser"]).findOne({
where: { auth0Subject },
})
if (existingUser) {
return existingUser
}
const firstTimeUser = await User.withScope(["asCurrentUser"]).findOne({
where: { [Op.or]: [{ auth0Subject: email }, { email: email }] },
})
if (firstTimeUser) {
await firstTimeUser.update({ auth0Subject })
return firstTimeUser
}
throw new Error("No user found for this token.")
}
}
export default FindFromAuth0TokenService
+1
View File
@@ -4,3 +4,4 @@ export { DestroyService } from "./destroy-service"
// Special Services
export { EnsureFromAuth0TokenService } from "./ensure-from-auth0-token-service"
export { FindFromAuth0TokenService } from "./find-from-auth0-token-service"
+2 -12
View File
@@ -23,16 +23,6 @@
>
CALEBBURKEDEV
</h2>
<div
class="card-subtitle mb-6"
style="font-size: 1.2rem"
>
Helicopter Maintenance Tracking Platform
</div>
<p>
This application is will streamline maintenance control decision making and unlock
operational constraints.
</p>
<h6 class="text-h6 text-medium-emphasis d-flex align-center mt-6 font-weight-medium">
<v-btn
block
@@ -42,12 +32,12 @@
>
</h6>
<!--
<div class="my-6 text-medium-emphasis">
If you don't have an account, create one to get started using ROTYR. It's free to sign
up and only takes a few seconds.
</div>
<!-- <v-btn
<v-btn
block
variant="outlined"
color="primary"