not even sure
This commit is contained in:
@@ -10,9 +10,12 @@ import { type Id } from './_generated/dataModel';
|
||||
import { action, mutation, query } from './_generated/server';
|
||||
import Authentik from '@auth/core/providers/authentik';
|
||||
import { Entra, Password, validatePassword } from './custom/auth';
|
||||
import Resend from '@auth/core/providers/resend';
|
||||
import { Resend as ResendAPI } from 'resend';
|
||||
import { generateRandomString, RandomReader } from '@oslojs/crypto/random';
|
||||
|
||||
export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
|
||||
providers: [Password, Authentik, Entra],
|
||||
providers: [Authentik, Entra, Password],
|
||||
});
|
||||
|
||||
export const PASSWORD_MIN = 8;
|
||||
@@ -172,3 +175,32 @@ export const updateUserPassword = action({
|
||||
return { success: true };
|
||||
},
|
||||
});
|
||||
|
||||
//export const ResendOTPPasswordReset = Resend({
|
||||
//id: "resend-otp",
|
||||
//apiKey: process.env.AUTH_RESEND_KEY,
|
||||
//async generateVerificationToken() {
|
||||
//const random: RandomReader = {
|
||||
//read(bytes) {
|
||||
//crypto.getRandomValues(bytes);
|
||||
//},
|
||||
//};
|
||||
|
||||
//const alphabet = "0123456789";
|
||||
//const length = 8;
|
||||
//return generateRandomString(random, alphabet, length);
|
||||
//},
|
||||
//async sendVerificationRequest({ identifier: email, provider, token }) {
|
||||
//const resend = new ResendAPI(provider.apiKey);
|
||||
//const { error } = await resend.emails.send({
|
||||
//from: "My App <onboarding@resend.dev>",
|
||||
//to: [email],
|
||||
//subject: `Reset your password in My App`,
|
||||
//text: "Your password reset code is " + token,
|
||||
//});
|
||||
|
||||
//if (error) {
|
||||
//throw new Error("Could not send");
|
||||
//}
|
||||
//},
|
||||
//});
|
||||
|
@@ -58,29 +58,33 @@ export const create = mutation({
|
||||
updatedBy: v.optional(v.id('users')),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const authUserId = await getAuthUserId(ctx);
|
||||
const authUserId: Id<'users'> | null = await getAuthUserId(ctx);
|
||||
if (!args.userId && !authUserId) {
|
||||
throw new ConvexError('Not authenticated.');
|
||||
}
|
||||
|
||||
const userId = args.userId ?? authUserId!;
|
||||
const updatedBy = args.updatedBy ?? authUserId!;
|
||||
|
||||
await ensureUser(ctx, userId);
|
||||
await ensureUser(ctx, updatedBy);
|
||||
|
||||
const message = args.message.trim();
|
||||
if (message.length === 0) {
|
||||
throw new ConvexError('Message cannot be empty.');
|
||||
}
|
||||
|
||||
const statusId = await ctx.db.insert('statuses', {
|
||||
message,
|
||||
userId,
|
||||
updatedBy,
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
|
||||
const userId = args.userId ?? authUserId!;
|
||||
const updatedBy = args.updatedBy ?? authUserId;
|
||||
await ensureUser(ctx, userId);
|
||||
let statusId: Id<'statuses'>;
|
||||
if (updatedBy) {
|
||||
ensureUser(ctx, updatedBy);
|
||||
statusId = await ctx.db.insert('statuses', {
|
||||
message,
|
||||
userId,
|
||||
updatedBy,
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
} else {
|
||||
statusId = await ctx.db.insert('statuses', {
|
||||
message,
|
||||
userId,
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
}
|
||||
await ctx.db.patch(userId, { currentStatusId: statusId });
|
||||
return { statusId };
|
||||
},
|
||||
@@ -125,7 +129,6 @@ export const bulkCreate = mutation({
|
||||
},
|
||||
});
|
||||
|
||||
// Update all users - simplified
|
||||
export const updateAllStatuses = mutation({
|
||||
args: { message: v.string() },
|
||||
handler: async (ctx, args) => {
|
||||
@@ -152,22 +155,19 @@ export const updateAllStatuses = mutation({
|
||||
},
|
||||
});
|
||||
|
||||
// Lunch status with automatic return - this should be an action
|
||||
export const createLunchStatus = mutation({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const authUserId = await getAuthUserId(ctx);
|
||||
if (!authUserId) throw new ConvexError('Not authenticated.');
|
||||
// Create lunch status
|
||||
await ctx.runMutation(api.statuses.create, {
|
||||
message: 'At lunch',
|
||||
userId: authUserId
|
||||
userId: authUserId,
|
||||
});
|
||||
const oneHour = 60 * 60 * 1000;
|
||||
console.log('Scheduling return to desk after 1 hour');
|
||||
await ctx.scheduler.runAfter(oneHour, api.statuses.create, {
|
||||
message: 'At desk',
|
||||
userId: authUserId
|
||||
userId: authUserId,
|
||||
});
|
||||
return { success: true };
|
||||
},
|
||||
@@ -257,7 +257,10 @@ export const listHistory = query({
|
||||
userId: v.optional(v.id('users')),
|
||||
paginationOpts: paginationOptsValidator,
|
||||
},
|
||||
handler: async (ctx, { userId, paginationOpts }): Promise<Paginated<StatusRow>> => {
|
||||
handler: async (
|
||||
ctx,
|
||||
{ userId, paginationOpts },
|
||||
): Promise<Paginated<StatusRow>> => {
|
||||
const result = userId
|
||||
? await ctx.db
|
||||
.query('statuses')
|
||||
|
@@ -11,7 +11,9 @@
|
||||
"author": "Gib",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"convex": "^1.27.0"
|
||||
"@oslojs/crypto": "^1.0.1",
|
||||
"convex": "^1.27.0",
|
||||
"resend": "^6.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "5.9.2"
|
||||
|
Reference in New Issue
Block a user