PVC name template not working

I am trying to change my notebook root directory from /home/jovyan to /home/jovyan/{username}.
Initially i tried to use this inside extraConfig inside hub spawner.notebook_dir = f"/home/jovyan/{username}" but it didn’t work as the username was rendered as shaik\, sameer for spawner.user.name and shaik-5C-2C-20sameer in case of username inside singleuser.
so i tried this approach as the username was finally being rendered as shaiksameer but the pvc was being created as claim-shaik-5c-2c-20sameer
here is the code:

extraConfig:
  set_safe_username: |
    def safe_username(username):
        return username.replace(",", "").replace(" ", "").replace("\\", "").lower()
 
    def notebook_dir_hook(spawner):
        import logging
        raw_username = spawner.user.name
        safe_name = safe_username(raw_username)
        spawner.user.name = safe_name  # Needed for PVC, pod, etc.
        spawner.environment.update({
            "NB_USER": safe_name,
            "NB_UID": "1000"
        })
 
        spawner.notebook_dir = f"/home/jovyan/{safe_name}"
 
    c.KubeSpawner.pre_spawn_hook = notebook_dir_hook

singleuser:
  storage:
    type: dynamic
    extraLabels: {}
    extraVolumes: []
    extraVolumeMounts: []
    static:
      pvcName:
      subPath: "{username}"
    capacity: 1Gi # have change to 10Gi later
    homeMountPath: /home/jovyan/{username}
    dynamic:
      storageClass:
      pvcNameTemplate: claim-{username}{servername}
      volumeNameTemplate: volume-{username}{servername}
      storageAccessModes: [ReadWriteOnce]

why the pvc name template is not being created with safe_name

Note I’ve edited your post so that your code block is wrapped with triple backticks

spawner.user is set by JupyterHub, so you can’t rely on modifying the object. If you want to modify the username everywhere you can do that in your authenticator:

for example, you could override normalize_username

If i use this will it interfere with authentication while logging
I cant figure it out exactly where to put normalize username in the chart can you please help with it.