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 { try {
const token = req.headers.authorization || "" 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 req.currentUser = user
return next() return next()
} catch (error) { } 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 // Special Services
export { EnsureFromAuth0TokenService } from "./ensure-from-auth0-token-service" 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 CALEBBURKEDEV
</h2> </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"> <h6 class="text-h6 text-medium-emphasis d-flex align-center mt-6 font-weight-medium">
<v-btn <v-btn
block block
@@ -42,12 +32,12 @@
> >
</h6> </h6>
<!--
<div class="my-6 text-medium-emphasis"> <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 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. up and only takes a few seconds.
</div> </div>
<v-btn
<!-- <v-btn
block block
variant="outlined" variant="outlined"
color="primary" color="primary"