Fixing edge case bug in setup.
2 files changed, 4 insertions(+), 3 deletions(-)

M nlotp/__init__.py
M nlotp/views.py
M nlotp/__init__.py +1 -1
@@ 1,6 1,6 @@ 
 # -*- coding: utf-8 -*-
 default_app_config = "nlotp.apps.NLOTPConfig"
-VERSION = (0, 1, 1, "final", 0)
+VERSION = (0, 1, 2, "final", 0)
 
 
 def get_version():

          
M nlotp/views.py +3 -2
@@ 3,8 3,6 @@ import qrcode.image.svg
 from django.contrib import messages
 from django.contrib.auth.mixins import LoginRequiredMixin
 from django.http import HttpResponse
-from django.shortcuts import get_object_or_404
-from django.urls import reverse_lazy
 from django.views.generic.edit import FormView, View
 from django_otp import DEVICE_ID_SESSION_KEY
 from django_otp import login as otp_login

          
@@ 42,6 40,9 @@ class TwoFactorAuthView(LoginRequiredMix
 
     def setup(self, request, *args, **kwargs):
         super().setup(request, *args, **kwargs)
+        if not request.user.is_authenticated:
+            return
+
         self.totp_device = utils.get_user_totp_device(self.request.user)
         self.static_device = utils.get_user_static_device(self.request.user)
         self.generate_codes = "auth-generate_codes" in self.request.POST