Tony
Tony
Explore posts from servers
NNuxt
Created by Tony on 12/20/2024 in #❓・help
useCookie bugged, not keeping state
I am trying to build a system to keep track of user auth, using composables and useCookie. It works fine however the cookie is completely forgetting its token value between functions. Here's the code: https://pastebin.com/UiRnSPRc When the user calls logIn, the token is fetched and set to the cookie. At line 47 you can see I'm logging it and in my tests it is set to the correct value. However the logIn function then calls fetchUser, which accesses the same cookie - but on line 74 you can see it logs undefined for some reason. The cookies are both the same, to ensure it I defined a custom useTokenCookie. I'm really not sure what's happening and why the cookie just magically forgets it's set value?
6 replies
Aarktype
Created by Tony on 12/19/2024 in #questions
Optional required pairs?
I have a type that has all optional properties. However I want to want to make 2 options a pair - if one exists, the other is required. An example:
const props = type({
'propA?': 'string',
'propB?': 'string',
'propC?': 'string'
});

// valid
props({ propA: 'test' });

// not valid - propB requires propC as well, and vice versa
props({ propB: 'test' });
props({ propC: 'test' });

// valid - both provided
props({ propB: 'test', propC: 'test' });
const props = type({
'propA?': 'string',
'propB?': 'string',
'propC?': 'string'
});

// valid
props({ propA: 'test' });

// not valid - propB requires propC as well, and vice versa
props({ propB: 'test' });
props({ propC: 'test' });

// valid - both provided
props({ propB: 'test', propC: 'test' });
Is this doable? I'm using Arktype for validating incoming JSON in a server, so the use case for it is changing passwords, if you want to change your password you need to provide the current password as well, and maybe the new password a second time to confirm it
3 replies
NNuxt
Created by Tony on 6/4/2024 in #❓・help
useFetch refresh failing to recognise new query params
I have a simple page with this useFetch code at the start:
const { data, refresh } = await useFetch(`/api/images`, {
query: {
q: query.value
}
});

watch(() => route.query.q, async () => {
await refreshNuxtData();
await refresh();
});
const { data, refresh } = await useFetch(`/api/images`, {
query: {
q: query.value
}
});

watch(() => route.query.q, async () => {
await refreshNuxtData();
await refresh();
});
However refresh() won't use the new route query param. If I put {{ route.query.q }} in the page it shows the new query param but refreshing through the watch OR a button with refresh() manually shows the API as recieving the old query param What's happening???
7 replies
SIASapphire - Imagine a framework
Created by Tony on 2/24/2024 in #sapphire-support
Throwing errors in commands/subcommands
Just curious if there is a way to throw an error in an application command/subcommand and have it handled by the chatInputCommandDenied listener, similar to how preconditions work. Some kind of this.error that can be sent and handled by the listener. Does this exist or can I write something to do that?
17 replies
SIASapphire - Imagine a framework
Created by Tony on 2/23/2024 in #sapphire-support
Limit command to specified roles?
I honestly haven't done this in a while (not since pre-application commands) and am new to using Sapphire. Looking to restrict a command to only be visible/usable by the server's owner and any roles they define. How is this best handled with Sapphire and application commands? The bot in question has a database to store roles if that's needed. Using TypeScript, here's a basic command I wrote that I want to restrict as described:
// commands/example.ts
import { ApplyOptions } from '@sapphire/decorators';
import { Command } from '@sapphire/framework';

@ApplyOptions<Command.Options>({
description: 'An example command, that should only be accessed by server owner and users with roles defined'
})

export class UserCommand extends Command {
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
);
}

public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
return interaction.reply(`Command example!`);
}
}
// commands/example.ts
import { ApplyOptions } from '@sapphire/decorators';
import { Command } from '@sapphire/framework';

@ApplyOptions<Command.Options>({
description: 'An example command, that should only be accessed by server owner and users with roles defined'
})

export class UserCommand extends Command {
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
);
}

public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
return interaction.reply(`Command example!`);
}
}
Already looked over docs and previous questions, though maybe I've missed something, call me out if I have haha
16 replies
NNuxt
Created by Tony on 4/29/2023 in #❓・help
Server /api returning 404, but still working
I have a server route in /server/api/download.post.ts. When fetching it, the route seems to return a 404 Cannot find any route matching /api/download. However, this makes no sense as the route works fine and the code inside the route actually works - just when it finishes (it's non-sync code I believe, tried promisify-ing it to no luck) the event.node.res.end won't work. Any help?
9 replies
NNuxt
Created by Tony on 2/10/2023 in #❓・help
useLazyFetch errors not resolving
No description
3 replies
NNuxt
Created by Tony on 11/26/2022 in #❓・help
Changing pages keeping the original page content until refresh
No description
6 replies