mirror of
https://github.com/aljazceru/landscape-template.git
synced 2025-12-18 14:54:23 +01:00
feat: basic nostr-settings profile section
This commit is contained in:
@@ -198,6 +198,8 @@ export interface NexusGenObjects {
|
||||
linkedin?: string | null; // String
|
||||
location?: string | null; // String
|
||||
name: string; // String!
|
||||
nostr_prv_key?: string | null; // String
|
||||
nostr_pub_key?: string | null; // String
|
||||
role?: string | null; // String
|
||||
twitter?: string | null; // String
|
||||
website?: string | null; // String
|
||||
@@ -405,6 +407,8 @@ export interface NexusGenFieldTypes {
|
||||
linkedin: string | null; // String
|
||||
location: string | null; // String
|
||||
name: string; // String!
|
||||
nostr_prv_key: string | null; // String
|
||||
nostr_pub_key: string | null; // String
|
||||
role: string | null; // String
|
||||
stories: NexusGenRootTypes['Story'][]; // [Story!]!
|
||||
twitter: string | null; // String
|
||||
@@ -611,6 +615,8 @@ export interface NexusGenFieldTypeNames {
|
||||
linkedin: 'String'
|
||||
location: 'String'
|
||||
name: 'String'
|
||||
nostr_prv_key: 'String'
|
||||
nostr_pub_key: 'String'
|
||||
role: 'String'
|
||||
stories: 'Story'
|
||||
twitter: 'String'
|
||||
|
||||
@@ -242,6 +242,8 @@ type User {
|
||||
linkedin: String
|
||||
location: String
|
||||
name: String!
|
||||
nostr_prv_key: String
|
||||
nostr_pub_key: String
|
||||
role: String
|
||||
stories: [Story!]!
|
||||
twitter: String
|
||||
|
||||
@@ -23,6 +23,8 @@ const User = objectType({
|
||||
t.string('linkedin')
|
||||
t.string('bio')
|
||||
t.string('location')
|
||||
t.string('nostr_prv_key')
|
||||
t.string('nostr_pub_key')
|
||||
|
||||
t.nonNull.list.nonNull.field('stories', {
|
||||
type: "Story",
|
||||
@@ -55,10 +57,15 @@ const profile = extendType({
|
||||
args: {
|
||||
id: nonNull(intArg())
|
||||
},
|
||||
async resolve(parent, { id }) {
|
||||
return prisma.user.findFirst({
|
||||
where: { id }
|
||||
})
|
||||
async resolve(parent, { id }, ctx) {
|
||||
const user = await getUserByPubKey(ctx.userPubKey);
|
||||
const isSelf = user?.id === id;
|
||||
const profile = await prisma.user.findFirst({
|
||||
where: { id },
|
||||
});
|
||||
if (!isSelf)
|
||||
profile.nostr_prv_key = null;
|
||||
return profile;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ const { createExpressApp } = require('../../modules');
|
||||
const express = require('express');
|
||||
const jose = require('jose');
|
||||
const { JWT_SECRET } = require('../../utils/consts');
|
||||
const { generatePrivateKey, getPublicKey } = require('../../utils/nostr-tools');
|
||||
|
||||
|
||||
|
||||
@@ -28,11 +29,17 @@ const loginHandler = async (req, res) => {
|
||||
//Create user if not already existing
|
||||
const user = await prisma.user.findFirst({ where: { pubKey: key } })
|
||||
if (user === null) {
|
||||
|
||||
const nostr_prv_key = generatePrivateKey();
|
||||
const nostr_pub_key = getPublicKey(nostr_prv_key);
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
pubKey: key,
|
||||
name: key,
|
||||
avatar: `https://avatars.dicebear.com/api/bottts/${key}.svg`
|
||||
avatar: `https://avatars.dicebear.com/api/bottts/${key}.svg`,
|
||||
nostr_prv_key,
|
||||
nostr_pub_key,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user