0
votes

I have a login component. I Want some code to run when I'm in development mode at the moment. The code is just a "laziness" thing that should only run when in development, where I log in with my own local test user.

My code snippet:

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    await base.OnAfterRenderAsync(firstRender);
    var authen = await Session.AuthenticateAsync("TestSite", "TestUser", "12345678");
    if (authen)
    {
        NavigationManager.NavigateTo("users");
    }
}

Can I wrap my statement here in an if statement like so:

if (Environment.ASPCORE_ENVIRONMENT == "Development") {
    // Do my lazy ass hack
}
1

1 Answers

0
votes

... Aaand right after I post my question I found the answer.. Rubber duck debugging :P

enter image description here

You can access the Environment like so:

var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

if(env == "Development")
{
    var authen = await Session.AuthenticateAsync("TestSite", "TestUser", "12345678");
    if (authen)
    {
        NavigationManager.NavigateTo("users");
    }
}

Tadaaaaa...