VIRTUAL DAN

VIRTUAL DAN

Notes from my travels around the internet

VIRTUAL DAN
  • My Pacific Northwest Solar
  • About
Monthly Archives: September 2020

My Custom Blazor Authentication

I have been building out my first Blazor application, and have been figuring out the pattern I want to follow for user authentication. Rather than use the built in Blazor authentication components, I am using the libraries I have built over the years, and I can plug into almost any app without having to think.

Where I got tripped up a bit with Blazor was in communicating the logged in an logged out status across components. After lots of Googling and experimenting, here is what I came up with:

In my Blazor Mainlayout page, I embedded the login bar component directly. This login bar just shows a login button, or if the user is logged in shows a logout button and the users name. When the signin button is clicked, the logon bar launches a login form component to collect username and password, and call the authentication API with the credentials. When a login is successful, the login bar updates a singleton class applicationvars.cs that holds all the profile information. This singleton allows all pages in the application to access these values. This is a nice, compact, and elegant way to handle what we used to call global and session variables – and is rapidly becoming one of my favorite things about Blazor.

Where I got tripped up was when I wanted to enforce a logout, or deal with a user session expired situation and message it appropriately. I finally settled on the solution of adding multiple routes to the same index page. I built route called ‘/logout’ and ‘/expired’, and added that route to the index page:

Where I erred was I put the logic to destroy the credentials in applicationvars inside the index page, which renders after the login bar, so the login bar didn’t reflect the credentials change. I futzed around with trying to get the index page to fire an event when the logout is detected, and have the login bar listen for the event and update appropriately. The better solution was to have the loginbar sniff the url, and when it sees the logout or expired URL, it destroys the credentials and redirects to the appropriate index URL. It was a much more elegant solution than getting the event wired up. It makes me wonder – maybe a new rule I need to follow: for your average business application, if you have to fire an event, you are probably doing something wrong in your design.

This design is working, and so far it has nicely isolated the authentication logic from the rest of the application. One worry is there is no easy way to have the app communicate with the login bar, so I may have isolated it too much. In recent various Blazor blog posts, I have noticed people are moving away from the singleton approach in favor of wrapping application vars around the whole application in the router. This new technique doesn’t change the over concept, so I may adapt that pattern in my next project. But for now, I will proceed with this pattern, and see how many times this paints me into a corner I don’t want to be in.

Buy Now
C# 10 and .NET 6 – Modern Cross-Platfo…
Read More
Buy Now
Murach’s ASP.NET Core MVC (Paperback)
Read More
Buy Now
New Era Unisex Core Classic Knit Brook…
Read More
September 21, 2020 Dan Leave a comment

The Bond Dilemma

The craziness of markets over the last few months caused by the Coronavirus have been incredible. As in investor, I am trying to forecast where we go from here, and what are the best and worst possible outcomes. While the stock market and its disconnect from the economy seems to be getting most of the headlines, I think the bigger story is the bond market and where it goes from here.

As seen in the chart above, the 2 year treasury bond has dropped from near 3.00% in late 2018 to 0.13% in September of 2020. This, along with the government’s fiscal stimulus is probably most responsible for the stock market’s disconnect from the economy.

The stimulus here is unprecedented – dwarfing the financial crisis of 2009:

The stock market is fueled by stimulus, and seems to be signalling full speed ahead. Given the government intervention, it is nearly impossible to determine if the market is overvalued or undervalued, as the economy is a secondary factor to stimulus.

I also think the stock market is being fueled by Bond investors jumping ship. Risk averse bond investors not reinvesting bonds that mature at .14% – instead invest in Apple or Microsoft that has a growing yield and is ‘safe’. I understand the appeal of this strategy, but at these prices it seems like a lot or risk is being taken on out of desperation.

At any rate, one almost sure bet is that the bond market will be a loser. This bet does assume that the aversion to negative interest rates in the US will persist. Given that assumption, the best case for the investors in 2 year treasuries would be a no inflation or deflationary economy, with rates at or near zero. Given that assumption, the rate of return on bonds is still near zero.

The worst case scenario for bond investors is all this stimulus in the hands of consumers, combined with an economy waking from the COVID shutdown, leads to inflation. The only hope the government has of reducing the debt is to increase inflation, and so those in charge of the money press are incented to cause some inflation. The government has targeted and pretty much achieved a 2% inflation rate for the last few years. The Federal Reserve recently adjusted its inflation mandate to declare they may allow overshooting their 2% target rate – a further sign of inflation in the medium to long term. This does not bode well for a T-Bill yielding .14%.

So what to do with my bond portfolio. My asset allocation currently has a percentage in US Bonds, and if I am to reduce that allocation, where to I put it? Lots of options, but none that I really like:

  1. Increase Allocation to the stock market.  One option is to increase allocation to the stock market- maybe in the ‘bond proxy’ sectors. Options such as Utilities and Financials (JP Morgan is yielding over 3.6%%, and the government won’t let anything happen to that bank. Most local and regional ‘safe’ utilities yield in the 2-4 % range. Other options might be focusing on reasonable yielding low valuation stocks. Rocky Brands comes to mind with a near 2% yield and Price/Book around 1, P/E of 9, and a little growth.  Many bond investors have already flocked to the market and these sectors, so it may be too late here to buy these possibly inflated assets.  Definitely adding risk with this strategy.
  2. Increase Allocation to Gold.  I have an allocation in gold already, though I hate the idea of holding rocks in my portfolio. But the way the world if printing money, Gold has had a pretty good year and the money printing wont be stopping anytime soon. I have been experimenting with buying quality Gold miners, then selling covered calls in the +10% range which generates pretty good income. This is still an experimental strategy, but it seems to be doing no worse than just holding gold (via BAR) and gold mining stocks, and makes me feel better about holding this asset class.
  3. Increase Allocation to TIPS (Treasury Inflation Protection Securities).  An interesting play here – TIPS are pegged to the inflation rate – so if inflation does hit, your interest rate increases. If we have deflation, yields will turn negative (unless you buy IBonds via Treasury Direct – which have a floor of 0% rate – but there is a limit on annual purchases). Probably worth taking your chances with TIPS over fixed rate bonds, The Vanguard TIPS Mutual Fund is currently yielding over 2%, so that might be an interesting option, but its not going to make you rich.  Its also moved up alot over the last few months, as other people have figured this out several months ago.
  4. Increase Allocation to Real Estate/REITs.  This is my least favorite diversification play. In volatile times, REITs move more like stocks than bonds, so its a huge risk increase to move from bonds to economy dependant real estate. There are certain areas of REITs that my be interesting for ‘safer’ diversification (i.e. farmland REITs), but historically they haven’t performed well.  I also believe the fallout from COVID has yet to be reflected in the commercial REITS.

I am not alone facing these choices – most investors saving for retirement or in retirement are facing this dilemma. Right now I am leaning toward increasing my allocations to the stock market – but really emphasizing low P/E or low Price to Book stocks in defensive sectors that haven’t participated in this recent tech bubble run-up. Those stocks are out there, it just requires some digging.

Buy Now
Stocks, Bonds, and Investing: Oh, My! (Software Download)
Read More
Buy Now
Why Bother With Bonds: A Guide To Build All-Weather Portfolio Including CDs…
Read More
Buy Now
The Strategic Bond Investor, Third Edition: Strategic Tools to Unlock the P…
Read More
September 2, 2020 Dan Leave a comment

Archives

  • August 2021 (1)
  • May 2021 (1)
  • April 2021 (1)
  • March 2021 (1)
  • February 2021 (1)
  • January 2021 (1)
  • December 2020 (2)
  • November 2020 (2)
  • October 2020 (2)
  • September 2020 (2)
  • August 2020 (2)
  • July 2020 (2)
  • June 2020 (2)
  • May 2020 (2)
  • April 2020 (2)
  • March 2020 (2)
  • February 2020 (2)
  • January 2020 (3)
  • December 2019 (2)
  • November 2019 (2)
  • October 2019 (2)
  • September 2019 (1)
  • August 2019 (2)
  • July 2019 (2)
  • June 2019 (1)
  • May 2019 (3)
  • April 2019 (2)
  • March 2019 (2)
  • February 2019 (2)
  • January 2019 (3)
  • December 2018 (2)
  • November 2018 (2)
  • October 2018 (2)
  • September 2018 (2)
  • August 2018 (2)
  • July 2018 (2)
  • June 2018 (2)
  • May 2018 (2)
  • April 2018 (2)
  • March 2018 (2)
  • February 2018 (1)
  • January 2018 (3)
  • December 2017 (2)
  • November 2017 (2)
  • October 2017 (2)
  • September 2017 (2)
  • August 2017 (2)
  • July 2017 (2)
  • June 2017 (3)
  • May 2017 (2)
  • April 2017 (1)
  • March 2017 (3)
  • February 2017 (3)
  • January 2017 (2)
  • December 2016 (2)
  • November 2016 (3)
  • October 2016 (2)
  • September 2016 (2)
  • August 2016 (2)
  • July 2016 (2)
  • June 2016 (2)
  • May 2016 (2)
  • April 2016 (2)
  • March 2016 (2)
  • February 2016 (3)
  • January 2016 (4)
  • December 2015 (2)
  • November 2015 (2)
  • October 2015 (3)
  • September 2015 (3)
  • August 2015 (2)
  • July 2015 (4)
  • June 2015 (2)
  • May 2015 (4)
  • April 2015 (3)
  • March 2015 (4)
  • February 2015 (4)
  • January 2015 (4)
  • December 2014 (5)
  • November 2014 (3)
  • October 2014 (5)
  • September 2014 (3)
  • August 2014 (5)
  • July 2014 (4)
  • June 2014 (4)
  • May 2014 (3)
  • April 2014 (3)
  • March 2014 (5)
  • February 2014 (2)
  • January 2014 (5)
  • December 2013 (4)
  • November 2013 (6)
  • October 2013 (3)
  • September 2013 (3)
  • August 2013 (4)
  • July 2013 (3)
  • June 2013 (3)
  • May 2013 (5)
  • April 2013 (2)
  • March 2013 (6)
  • February 2013 (6)
  • January 2013 (5)
  • December 2012 (5)
  • November 2012 (4)
  • October 2012 (3)
  • September 2012 (4)
  • August 2012 (3)
  • July 2012 (3)
  • June 2012 (2)
  • May 2012 (3)
  • March 2012 (3)
  • February 2012 (2)
  • January 2012 (1)
  • December 2011 (3)
  • November 2011 (3)
  • October 2011 (2)
  • September 2011 (2)
  • August 2011 (3)
  • July 2011 (4)
  • June 2011 (4)
  • May 2011 (3)
  • April 2011 (6)
  • March 2011 (8)
WEBSITE DISCLAIMER: The operator of this site (Vertical Financial Systems, Inc) are not registered investment advisers, broker/dealers, or research analysts/organizations. The content on this website is issued solely for information purposes and should not to be construed as an offer to buy, sell, or trade in any way, any security mentioned herein. All information presented on this website is believed to be reliable and written in good faith, but no representation or warranty, expressed or implied is made as to their accuracy, completeness or correctness. You are responsible for doing your own research before investing in any securities mentioned herein. Readers are urged to consult with their own independent financial advisors with respect to any investment. Neither Vertical Financial Systems, Inc, nor its officers or employees accept any liability whatsoever for any direct or consequential loss arising from any use of information on this website.
Full Disclosure: As an Amazon Associate I earn from qualifying purchases
Powered by WordPress | theme SG Simple